Sha256: 6eb7c7fe3e4517558782adf2db2798dbcf2be8d4de4458cade18a38b7e50e5d0

Contents?: true

Size: 894 Bytes

Versions: 18

Compression:

Stored size: 894 Bytes

Contents

module Origen
  module Tester
    module Parser
      class SearchableArray < ::Array
        def where(conditions)
          exact = conditions.delete(:exact)
          results = SearchableArray.new
          each do |item|
            if conditions.all? do |attr, val|
                 if val.is_a?(Array)
                   if exact
                     val.any? { |v| item.send(attr).to_s == v.to_s }
                   else
                     val.any? { |v| item.send(attr).to_s =~ /#{v.to_s}/ }
                   end
                 else
                   if exact
                     item.send(attr).to_s == val.to_s
                   else
                     item.send(attr).to_s =~ /#{val.to_s}/
                   end
                 end
               end
              results << item
            end
          end
          results
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
origen-0.2.6 lib/origen/tester/parser/searchable_array.rb
origen-0.2.5 lib/origen/tester/parser/searchable_array.rb
origen-0.2.4 lib/origen/tester/parser/searchable_array.rb
origen-0.2.3 lib/origen/tester/parser/searchable_array.rb
origen-0.2.2 lib/origen/tester/parser/searchable_array.rb
origen-0.2.1 lib/origen/tester/parser/searchable_array.rb
origen-0.2.0 lib/origen/tester/parser/searchable_array.rb
origen-0.1.3 lib/origen/tester/parser/searchable_array.rb
origen-0.1.2 lib/origen/tester/parser/searchable_array.rb
origen-0.1.1 lib/origen/tester/parser/searchable_array.rb
origen-0.1.0 lib/origen/tester/parser/searchable_array.rb
origen-0.0.9 lib/origen/tester/parser/searchable_array.rb
origen-0.0.8 lib/origen/tester/parser/searchable_array.rb
origen-0.0.6 lib/origen/tester/parser/searchable_array.rb
origen-0.0.5 lib/origen/tester/parser/searchable_array.rb
origen-0.0.4 lib/origen/tester/parser/searchable_array.rb
origen-0.0.3 lib/origen/tester/parser/searchable_array.rb
origen-0.0.2 lib/origen/tester/parser/searchable_array.rb