Module: Lexdrill::Inspector

Defined in:
lib/lexdrill/inspector.rb

Overview

Builds a human-readable snapshot of lexdrill's current config/state, for drill inspect — which files are active, how many words, the counter value, and whether drilling is currently stopped.

Class Method Summary collapse

Class Method Details

.beat_summaryObject



49
50
51
52
53
54
# File 'lib/lexdrill/inspector.rb', line 49

def self.beat_summary
  return "random (ignores rhythm/counter)" if Lexdrill::Beat.rand?
  return "not set (plain word-by-word)" unless Lexdrill::Beat.configured?

  "loop #{Lexdrill::Beat.loop_size}, repeat #{Lexdrill::Beat.repetitions}"
end

.counter_valueObject



33
34
35
# File 'lib/lexdrill/inspector.rb', line 33

def self.counter_value
  Lexdrill::Counter.new(Lexdrill::WordList::COUNTER_PATH).value
end

.rand_summaryObject



56
57
58
59
60
61
# File 'lib/lexdrill/inspector.rb', line 56

def self.rand_summary
  denominator = Lexdrill::Rand.value
  return "every time (default)" if denominator == 1

  "approximately 1-in-#{denominator}"
end

.reportObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lexdrill/inspector.rb', line 7

def self.report
  <<~REPORT
    drill #{Lexdrill::VERSION}

    Words file:    #{Lexdrill::WordList::PATH} (#{words_summary})
    Counter file:  #{Lexdrill::WordList::COUNTER_PATH} (value: #{counter_value})
    Stats file:    #{Lexdrill::Stats::PATH} (#{stats_summary})
    Toggle:        #{toggle_summary}
    Beat:          #{beat_summary}
    Rand:          #{rand_summary}
    Format:        #{Lexdrill::Format.current}
    LEXDRILL_PATH: #{ENV.fetch('LEXDRILL_PATH', '(not set)')}
  REPORT
end

.stats_summaryObject



37
38
39
40
41
# File 'lib/lexdrill/inspector.rb', line 37

def self.stats_summary
  return "no data yet" unless File.exist?(Lexdrill::Stats::PATH)

  "#{Lexdrill::Stats.counts.size} item(s) tracked"
end

.toggle_summaryObject



43
44
45
46
47
# File 'lib/lexdrill/inspector.rb', line 43

def self.toggle_summary
  return "enabled" if Lexdrill::Toggle.enabled?

  "stopped (#{Lexdrill::Toggle::PATH})"
end

.words_summaryObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/lexdrill/inspector.rb', line 22

def self.words_summary
  return "missing" unless File.exist?(Lexdrill::WordList::PATH)

  words = Lexdrill::WordList.words
  total = words.size
  graduated = words.count { |word| Lexdrill::Stats.graduated?(word) }
  return "#{total} word(s)" if graduated.zero?

  "#{total} word(s), #{graduated} graduated"
end