Class: HashComparator::ReverseMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_comparator/reverse_matcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_function:, hashed_items:, plaintext_items:) ⇒ ReverseMatcher

Returns a new instance of ReverseMatcher.



14
15
16
17
18
# 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

Instance Attribute Details

#hash_functionObject

Returns the value of attribute hash_function.



20
21
22
# File 'lib/hash_comparator/reverse_matcher.rb', line 20

def hash_function
  @hash_function
end

#hashed_itemsObject

Returns the value of attribute hashed_items.



20
21
22
# File 'lib/hash_comparator/reverse_matcher.rb', line 20

def hashed_items
  @hashed_items
end

#plaintext_itemsObject

Returns the value of attribute plaintext_items.



20
21
22
# File 'lib/hash_comparator/reverse_matcher.rb', line 20

def plaintext_items
  @plaintext_items
end

Class Method Details

.execute(hash_function:, hashed_items:, plaintext_items:) ⇒ Object



6
7
8
9
10
11
12
# 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

Instance Method Details

#executeObject



22
23
24
25
26
27
28
29
30
31
32
33
# 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