Class: Passphrase::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/passphrase/wordlist_database.rb

Overview

This class encapsulates the #where query against the “words” table in the “words” SQLite 3 database. The filter parameter must be a hash that specifies a language and sequence of die rolls.

Examples:

{language: "afrikaans", die_rolls: "11111"}

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ Word

Returns a new instance of Word.



58
59
60
# File 'lib/passphrase/wordlist_database.rb', line 58

def initialize(db)
  @db = db
end

Instance Method Details

#where(filter) ⇒ String

Returns a string of space-separated words from the wordlist.

Parameters:

  • filter (Hash)

    specifies the language/die_roll combination

Returns:

  • (String)

    a string of space-separated words from the wordlist



64
65
66
67
68
69
# File 'lib/passphrase/wordlist_database.rb', line 64

def where(filter)
  sql = "SELECT words " + 
        "FROM words " + 
        "WHERE language = :language AND die_rolls = :die_rolls"
  @db.get_first_value(sql, filter)
end