Class: Passphrase::DicewareMethod
- Inherits:
-
Object
- Object
- Passphrase::DicewareMethod
- Defined in:
- lib/passphrase/diceware_method.rb
Overview
This class implements the Diceware Method for generating a passphrase. It selects words from a multi-language wordlist stored in an SQLite 3 database. A special DicewareRandom class is provided to work with this class to simulate rolls of a die.
Class Method Summary collapse
-
.run(options) ⇒ Array<Array>
A convenience method for simultaneously creating a new DicewareMethod object and calling #run.
Instance Method Summary collapse
-
#initialize(options) ⇒ DicewareMethod
constructor
A new instance of DicewareMethod.
-
#run ⇒ Array<Array>
Runs the Diceware method and returns its result to the calling Passphrase object.
Constructor Details
#initialize(options) ⇒ DicewareMethod
Returns a new instance of DicewareMethod.
18 19 20 21 22 23 24 |
# File 'lib/passphrase/diceware_method.rb', line 18 def initialize() @number_of_words = [:number_of_words] @random = DicewareRandom.new([:use_random_org]) db = WordlistDatabase.connect @languages = db.from(:languages).only([:languages]) @words = db.from(:words) end |
Class Method Details
.run(options) ⇒ Array<Array>
A convenience method for simultaneously creating a new DicewareMethod object and calling #run
13 14 15 |
# File 'lib/passphrase/diceware_method.rb', line 13 def self.run() new().run end |
Instance Method Details
#run ⇒ Array<Array>
Runs the Diceware method and returns its result to the calling Passphrase object.
30 31 32 33 34 35 |
# File 'lib/passphrase/diceware_method.rb', line 30 def run get_random_languages get_random_die_rolls select_words_from_wordlist [@random_languages, @random_die_rolls, @selected_words] end |