Class: Tester::Parser::SearchableArray

Inherits:
Array
  • Object
show all
Defined in:
lib/origen_testers/parser/searchable_array.rb

Instance Method Summary collapse

Instance Method Details

#where(conditions) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/origen_testers/parser/searchable_array.rb', line 4

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