Class: DeepClassCompare::HashMatcher
- Includes:
- ContainerComparable
- Defined in:
- lib/deep_class_compare/hash_matcher.rb
Instance Method Summary collapse
- #build_chain(key_comparable, value_comparable = nil) ⇒ Object
-
#initialize(klass = Hash) ⇒ HashMatcher
constructor
A new instance of HashMatcher.
- #match?(hash) ⇒ Boolean
- #of(key_comparable, value_comparable = nil) ⇒ Object
Methods inherited from Matcher
Constructor Details
#initialize(klass = Hash) ⇒ HashMatcher
Returns a new instance of HashMatcher.
4 5 6 |
# File 'lib/deep_class_compare/hash_matcher.rb', line 4 def initialize(klass = Hash) super(klass) end |
Instance Method Details
#build_chain(key_comparable, value_comparable = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/deep_class_compare/hash_matcher.rb', line 19 def build_chain(key_comparable, value_comparable = nil) key_comparable, value_comparable = Object, key_comparable if value_comparable.nil? @key_chain = parse_comparable_to_chain(key_comparable) @value_chain = parse_comparable_to_chain(value_comparable) end |
#match?(hash) ⇒ Boolean
8 9 10 |
# File 'lib/deep_class_compare/hash_matcher.rb', line 8 def match?(hash) super && compare_hash_with_chain(hash) end |
#of(key_comparable, value_comparable = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/deep_class_compare/hash_matcher.rb', line 12 def of(key_comparable, value_comparable = nil) raise_pattern_error! unless @key_chain.nil? && @value_chain.nil? dup.tap do |matcher| matcher.build_chain(key_comparable, value_comparable) end end |