Class: Lexdrill::WordList
- Inherits:
-
Object
- Object
- Lexdrill::WordList
- Defined in:
- lib/lexdrill/word_list.rb
Overview
Reads vocabulary words/phrases from the words file, one per line, and
advances a persisted counter to show "the current word" each time. On a
fresh install, seeds the file with a default starter list instead of
coming up empty. Words that have graduated (see Lexdrill::Stats) are
excluded from .next but remain in .words for list/stats to report.
Constant Summary collapse
Class Method Summary collapse
Class Method Details
.active_words ⇒ Object
34 35 36 |
# File 'lib/lexdrill/word_list.rb', line 34 def self.active_words words.reject { |word| Lexdrill::Stats.graduated?(word) } end |
.next ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/lexdrill/word_list.rb', line 25 def self.next active = active_words return nil if active.empty? word = Lexdrill::Beat.rand? ? active.sample : active[take_index(active.size)] Lexdrill::Stats.record(word) word end |
.take_index(size) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/lexdrill/word_list.rb', line 38 def self.take_index(size) counter = Lexdrill::Counter.new(COUNTER_PATH) cycle_length = Lexdrill::Beat.cycle_length(size) step = counter.bounded_value(cycle_length) counter.increment Lexdrill::Beat.index_for(size, step) end |