class HashComparator::ReverseMatcher

Attributes

hash_function[RW]
hashed_items[RW]
plaintext_items[RW]

Public Class Methods

execute(hash_function:, hashed_items:, plaintext_items:) click to toggle source
# File lib/hash_comparator/reverse_matcher.rb, line 6
def self.execute(hash_function:, hashed_items:, plaintext_items:)
  new(
    hash_function: hash_function,
    hashed_items: hashed_items,
    plaintext_items: plaintext_items
  ).execute
end
new(hash_function:, hashed_items:, plaintext_items:) click to toggle source
# File lib/hash_comparator/reverse_matcher.rb, line 14
def initialize(hash_function:, hashed_items:, plaintext_items:)
  @hash_function = hash_function
  @plaintext_items = plaintext_items
  @hashed_items = hashed_items
end

Public Instance Methods

execute() click to toggle source
# File lib/hash_comparator/reverse_matcher.rb, line 22
def execute
  subject_hashed_items = Hasher.hash(
    hash_function: hash_function,
    plaintext_items: plaintext_items
  )

  matches = plaintext_items.each_with_index.each_with_object([]) do |(item, i), list|
    list << item if hashed_items.include?(subject_hashed_items[i])
  end
  
  matches.uniq.sort
end