Class: Filter::Matchers::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/filter/matchers/hash.rb

Instance Attribute Summary

Attributes inherited from Base

#pattern

Instance Method Summary collapse

Methods inherited from Base

#and, #or

Constructor Details

#initialize(pattern) ⇒ Hash

Returns a new instance of Hash.



4
5
6
# File 'lib/filter/matchers/hash.rb', line 4

def initialize(pattern)
  @pattern = ::Hash[pattern.map { |k, v| [k.to_proc, Filter::Matcher.new(v)]}]
end

Instance Method Details

#===(other) ⇒ Object



8
9
10
11
12
# File 'lib/filter/matchers/hash.rb', line 8

def ===(other)
  pattern.all? do |attr, pattern|
    pattern === attr.call(other)
  end
end