Class: Passphrase::Language
- Inherits:
-
Object
- Object
- Passphrase::Language
- Defined in:
- lib/passphrase/wordlist_database.rb
Overview
Instance Method Summary collapse
-
#[](index) ⇒ String
The language corresponding to the given index.
-
#all ⇒ Array
All rows in the languages table.
-
#count ⇒ Integer
The number of rows in the languages table.
-
#initialize(db) ⇒ Language
constructor
A new instance of Language.
-
#only(language_list) ⇒ self
To allow chaining methods.
Constructor Details
#initialize(db) ⇒ Language
Returns a new instance of Language.
8 9 10 11 12 |
# File 'lib/passphrase/wordlist_database.rb', line 8 def initialize(db) @languages = [] sql = "SELECT language FROM languages" db.execute(sql).each { |lang| @languages << lang.first } end |
Instance Method Details
#[](index) ⇒ String
Returns the language corresponding to the given index.
21 22 23 |
# File 'lib/passphrase/wordlist_database.rb', line 21 def [](index) @languages[index] end |
#all ⇒ Array
Returns all rows in the languages table.
26 27 28 |
# File 'lib/passphrase/wordlist_database.rb', line 26 def all @languages end |
#count ⇒ Integer
Returns the number of rows in the languages table.
15 16 17 |
# File 'lib/passphrase/wordlist_database.rb', line 15 def count @languages.size end |
#only(language_list) ⇒ self
Returns to allow chaining methods.
32 33 34 35 36 37 38 39 |
# File 'lib/passphrase/wordlist_database.rb', line 32 def only(language_list) return self if /^all$/ =~ language_list.first validate(language_list) @languages.keep_if do |language| language_list.any? { |l| language.match("^#{l}") } end self end |