Sha256: 2acc748775ebe4d320a03b0c35874b531e17de8059d2bdf1da62a1e12719dd79
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true module IdentityParade module Matchers # This matcher checks the similarity of two hashes. For this purpose, it # iterates over all elements and creates a new matcher for every type. class HashMatcher < Matcher def score subs = sub_scores return nil if subs.empty? subs.sum / sub_scores.size.to_f end # @return [Float] The sum of all sub scores 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 # @return [Array<String>] the list of blacklisted keys # :reek:UtilityFunction because it's a shorthand def blacklisted_keys IdentityParade.config.blacklisted_keys end # @return [Array<String>] the list of permitted keys def permitted_keys left.keys.map(&:to_s) - blacklisted_keys end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
identity_parade-1.0.1 | lib/identity_parade/matchers/hash_matcher.rb |