Class: HashComparator::Hasher

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

Constant Summary collapse

SUPPORTED_HASH_FUNCTIONS =
{
  md5: Digest::MD5,
  sha1: Digest::SHA1,
  sha256: Digest::SHA2,
  sha512: Digest::SHA512
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_function:, plaintext_items:) ⇒ Hasher



16
17
18
19
# File 'lib/hash_comparator/hasher.rb', line 16

def initialize(hash_function:, plaintext_items:)
  @hash_function = SUPPORTED_HASH_FUNCTIONS[hash_function]
  @plaintext_items = plaintext_items
end

Instance Attribute Details

#hash_functionObject

Returns the value of attribute hash_function.



21
22
23
# File 'lib/hash_comparator/hasher.rb', line 21

def hash_function
  @hash_function
end

#plaintext_itemsObject

Returns the value of attribute plaintext_items.



21
22
23
# File 'lib/hash_comparator/hasher.rb', line 21

def plaintext_items
  @plaintext_items
end

Class Method Details

.hash(hash_function:, plaintext_items:) ⇒ Object



12
13
14
# File 'lib/hash_comparator/hasher.rb', line 12

def self.hash(hash_function:, plaintext_items:)
  new(hash_function: hash_function, plaintext_items: plaintext_items).hash
end

Instance Method Details

#hashObject



23
24
25
26
27
# File 'lib/hash_comparator/hasher.rb', line 23

def hash
  plaintext_items.map do |item|
    hash_function.hexdigest(item)
  end
end