Class: ScatterSwap::Hasher
- Inherits:
-
Object
- Object
- ScatterSwap::Hasher
- Defined in:
- lib/scatter_swap/hasher.rb
Instance Attribute Summary collapse
-
#length ⇒ Fixnum
readonly
The number of digits in the computed hashes.
-
#spin ⇒ Fixnum
readonly
A seed value to add some spice, so that different apps can have differently mapped hashes.
- #working_array ⇒ Array[Fixnum] readonly
Instance Method Summary collapse
-
#hash ⇒ String
Obfuscate the original integer value to a zero-padded String of #length digits.
-
#initialize(integer, spin = 0, length = 10) ⇒ Hasher
constructor
Construct a new
Hasher
. -
#reverse_hash ⇒ String
De-obfuscate the original integer value to a zero-padded String of #length digits.
Constructor Details
#initialize(integer, spin = 0, length = 10) ⇒ Hasher
Construct a new Hasher
.
18 19 20 21 22 23 24 |
# File 'lib/scatter_swap/hasher.rb', line 18 def initialize(integer, spin = 0, length = 10) @original_integer = integer.freeze @spin = (spin || 0).freeze @length = length.freeze zero_pad = integer.to_s.rjust(length, '0') @working_array = zero_pad.split('').collect { |d| d.to_i } end |
Instance Attribute Details
#length ⇒ Fixnum (readonly)
Returns the number of digits in the computed hashes.
8 9 10 |
# File 'lib/scatter_swap/hasher.rb', line 8 def length @length end |
#spin ⇒ Fixnum (readonly)
Returns A seed value to add some spice, so that different apps can have differently mapped hashes.
11 12 13 |
# File 'lib/scatter_swap/hasher.rb', line 11 def spin @spin end |
#working_array ⇒ Array[Fixnum] (readonly)
5 6 7 |
# File 'lib/scatter_swap/hasher.rb', line 5 def working_array @working_array end |
Instance Method Details
#hash ⇒ String
Obfuscate the original integer value to a zero-padded String of #length digits.
29 30 31 32 33 |
# File 'lib/scatter_swap/hasher.rb', line 29 def hash swap scatter completed_string end |
#reverse_hash ⇒ String
De-obfuscate the original integer value to a zero-padded String of #length digits.
38 39 40 41 42 |
# File 'lib/scatter_swap/hasher.rb', line 38 def reverse_hash unscatter unswap completed_string end |