Class: Passphrase::DicewareMethod

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DicewareMethod

Returns a new instance of DicewareMethod.

Parameters:

  • options (Hash)

    the options passed from the Passphrase object



18
19
20
21
22
23
24
# File 'lib/passphrase/diceware_method.rb', line 18

def initialize(options)
  @number_of_words = options[:number_of_words]
  @random = DicewareRandom.new(options[:use_random_org])
  db = WordlistDatabase.connect
  @languages = db.from(:languages).only(options[: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

Returns:

  • (Array<Array>)

    a three element array of the (1) random languages, (2) random die rolls, and (3) corresponding random words



13
14
15
# File 'lib/passphrase/diceware_method.rb', line 13

def self.run(options)
  new(options).run
end

Instance Method Details

#runArray<Array>

Runs the Diceware method and returns its result to the calling Passphrase object.

Returns:

  • (Array<Array>)

    a three element array of the (1) random languages, (2) random die rolls, and (3) corresponding random words



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