Class: StrongPassword::EntropyCalculator::EntropyResolver
- Inherits:
-
Object
- Object
- StrongPassword::EntropyCalculator::EntropyResolver
- Defined in:
- lib/strong_password/entropy_calculator.rb
Constant Summary collapse
- BASE_VALUE =
1
- REPEAT_WEAKENING_FACTOR =
0.75
Instance Attribute Summary collapse
-
#char_multiplier ⇒ Object
readonly
Returns the value of attribute char_multiplier.
Instance Method Summary collapse
-
#entropy_for(char) ⇒ Object
Returns the current entropy value for a character and weakens the entropy for future calls for the same character.
-
#initialize ⇒ EntropyResolver
constructor
A new instance of EntropyResolver.
Constructor Details
#initialize ⇒ EntropyResolver
60 61 62 |
# File 'lib/strong_password/entropy_calculator.rb', line 60 def initialize @char_multiplier = {} end |
Instance Attribute Details
#char_multiplier ⇒ Object (readonly)
Returns the value of attribute char_multiplier.
58 59 60 |
# File 'lib/strong_password/entropy_calculator.rb', line 58 def char_multiplier @char_multiplier end |
Instance Method Details
#entropy_for(char) ⇒ Object
Returns the current entropy value for a character and weakens the entropy for future calls for the same character.
66 67 68 69 70 71 72 73 |
# File 'lib/strong_password/entropy_calculator.rb', line 66 def entropy_for(char) ordinal_value = char.ord char_multiplier[ordinal_value] ||= BASE_VALUE char_value = char_multiplier[ordinal_value] # Weaken the value of this character for future occurrances char_multiplier[ordinal_value] = char_multiplier[ordinal_value] * REPEAT_WEAKENING_FACTOR return char_value end |