class IdentityParade::Matchers::HashMatcher

This matcher checks the similarity of two hashes. For this purpose, it iterates over all elements and creates a new matcher for every type.

Public Instance Methods

blacklisted_keys() click to toggle source

@return [Array<String>] the list of blacklisted keys :reek: UtilityFunction because it's a shorthand

# File lib/identity_parade/matchers/hash_matcher.rb, line 29
def blacklisted_keys
  IdentityParade.config.blacklisted_keys
end
permitted_keys() click to toggle source

@return [Array<String>] the list of permitted keys

# File lib/identity_parade/matchers/hash_matcher.rb, line 34
def permitted_keys
  left.keys.map(&:to_s) - blacklisted_keys
end
score() click to toggle source
# File lib/identity_parade/matchers/hash_matcher.rb, line 8
def score
  subs = sub_scores

  return nil if subs.empty?

  subs.sum / sub_scores.size.to_f
end
sub_scores() click to toggle source

@return [Float] The sum of all sub scores

# File lib/identity_parade/matchers/hash_matcher.rb, line 17
def sub_scores
  left.map do |key, value|
    next nil if blacklisted_keys.include?(key.to_s)

    next 0 unless right.key?(key)

    IdentityParade::Match.new(value, right[key]).score
  end.compact
end