Module: Lexdrill::LineFormatter

Defined in:
lib/lexdrill/line_formatter.rb

Overview

Formats a shown word for display, on one line: "index/totalSEPARATOR word" — index is the word's own 1-based position in the list, re-derived through Lexdrill::Beat so it stays meaningful even when a rhythm repeats steps. The counter/total and the separator are painted yellow, as one unit; the word is colored by its show count (see Lexdrill::Colorizer).

Constant Summary collapse

SEPARATOR =
""

Class Method Summary collapse

Class Method Details

.format(word) ⇒ Object



12
13
14
15
16
17
# File 'lib/lexdrill/line_formatter.rb', line 12

def self.format(word)
  total = Lexdrill::WordList.words.size
  count = Lexdrill::Stats.counts.fetch(word, 0)
  prefix = Lexdrill::Colorizer.paint_yellow("#{loop_index(total) + 1}/#{total}#{SEPARATOR}")
  "#{prefix} #{Lexdrill::Colorizer.paint_by_count(word, count)}"
end

.loop_index(total) ⇒ Object



19
20
21
22
23
# File 'lib/lexdrill/line_formatter.rb', line 19

def self.loop_index(total)
  counter = Lexdrill::Counter.new(Lexdrill::WordList::COUNTER_PATH)
  step_used = counter.value - 1
  Lexdrill::Beat.loop_info(total, step_used).index
end