Class: HashComparator::Hasher
- Inherits:
-
Object
- Object
- HashComparator::Hasher
- 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
-
#hash_function ⇒ Object
Returns the value of attribute hash_function.
-
#plaintext_items ⇒ Object
Returns the value of attribute plaintext_items.
Class Method Summary collapse
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(hash_function:, plaintext_items:) ⇒ Hasher
constructor
A new instance of Hasher.
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_function ⇒ Object
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_items ⇒ Object
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
#hash ⇒ Object
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 |