Sha256: c832502d45d87e4c61248089fd33d89b9e1a16dce937cb9914f1f18a601f5aeb

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

module OrigenTesters
  module Parser
    class SearchableHash < ::Hash
      def where(conditions)
        exact = conditions.delete(:exact)
        results = SearchableArray.new
        each do |key, 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
origen_testers-0.13.2 lib/origen_testers/parser/searchable_hash.rb
origen_testers-0.10.0 lib/origen_testers/parser/searchable_hash.rb