Class: AttrMatcher

Inherits:
Matcher show all
Defined in:
lib/matcher.rb

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from Matcher

Instance Method Details

#match(obj) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/matcher.rb', line 32

def match(obj)
  attribute = @query.keys.first
  if attribute.include?(".")
    value = obj
    attribute.split(".").each do |attr|
      value = value[attr]
      if value.nil?
        return false
      end
    end
  else
    value = obj[@query.keys.first]
  end
  predicate = @query.values.first
  if predicate.kind_of? Hash
    matcher = PredicateMatcher.new(predicate)
    return matcher.match(value)
  else
    return value == predicate
  end
end