class DeepClassCompare::HashMatcher
Public Class Methods
new(klass = Hash)
click to toggle source
Calls superclass method
# File lib/deep_class_compare/hash_matcher.rb, line 4 def initialize(klass = Hash) super(klass) end
Public Instance Methods
build_chain(key_comparable, value_comparable = nil)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# 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
Private Instance Methods
compare_hash_with_chain(hash)
click to toggle source
# File lib/deep_class_compare/hash_matcher.rb, line 26 def compare_hash_with_chain(hash) hash.all? do |key, value| compare_chain(key, @key_chain) && compare_chain(value, @value_chain) end end