Class: Passphrase::PassphraseString
- Inherits:
-
String
- Object
- String
- Passphrase::PassphraseString
- Defined in:
- lib/passphrase/passphrase_string.rb
Overview
This subclass of String implements the #to_password instance method for substituting a capital letter, number, and special character into a passphrase.
Instance Method Summary collapse
-
#initialize(passphrase, use_random_org) ⇒ PassphraseString
constructor
A new instance of PassphraseString.
-
#to_password ⇒ String
A new String that is the passwordized version of the passphrase.
Constructor Details
#initialize(passphrase, use_random_org) ⇒ PassphraseString
Returns a new instance of PassphraseString.
9 10 11 12 13 |
# File 'lib/passphrase/passphrase_string.rb', line 9 def initialize(passphrase, use_random_org) super(passphrase) @use_random_org = use_random_org @random = DicewareRandom.new(use_random_org) end |
Instance Method Details
#to_password ⇒ String
Returns a new String that is the passwordized version of the passphrase.
17 18 19 20 21 22 23 24 |
# File 'lib/passphrase/passphrase_string.rb', line 17 def to_password @scratch = self.gsub(/\s/, "_") capital_index, number_index, special_index = @random.indices(3, @scratch.length) select_and_substitute_capital_letter(capital_index) select_and_substitute_number(number_index) select_and_substitute_special_character(special_index) String.new(@scratch) end |