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



59
60
61
62
63
64
# File 'lib/lexdrill/inspector.rb', line 59

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



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

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

.rand_summaryObject



66
67
68
69
70
71
# File 'lib/lexdrill/inspector.rb', line 66

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
21
22
23
# 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}
    Color:         #{Lexdrill::Color.current}
    Auth mode:     #{Lexdrill::AuthMode.current || 'not configured'}
    Workbook:      #{workbook_summary}
    Sheet:         #{Lexdrill::Workbooks.current_sheet || 'not selected'}
    Config dir:    #{Lexdrill::Config::DIR}
  REPORT
end

.stats_summaryObject



47
48
49
50
51
# File 'lib/lexdrill/inspector.rb', line 47

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

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

.toggle_summaryObject



53
54
55
56
57
# File 'lib/lexdrill/inspector.rb', line 53

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

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

.words_summaryObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/lexdrill/inspector.rb', line 32

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

.workbook_summaryObject



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

def self.workbook_summary
  name = Lexdrill::Workbooks.current_name
  return "not selected" unless name

  "#{name} (#{Lexdrill::Workbooks.current_url})"
end