Module: Lexdrill::Stats

Defined in:
lib/lexdrill/stats.rb

Overview

Tracks how many times each word/phrase has been shown by next, persisted as a word => count JSON object in the stats file. Every BUCKET_SIZE shows moves a word into the next display-color bucket (see Lexdrill::Colorizer); once a word reaches GRADUATION_THRESHOLD shows it's considered mastered and next stops selecting it.

Constant Summary collapse

PATH =
Lexdrill::Config.path("stats")
BUCKET_SIZE =
10
GRADUATION_THRESHOLD =
120

Class Method Summary collapse

Class Method Details

.countsObject



21
22
23
# File 'lib/lexdrill/stats.rb', line 21

def self.counts
  load
end

.graduated?(word) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/lexdrill/stats.rb', line 25

def self.graduated?(word)
  counts.fetch(word, 0) >= GRADUATION_THRESHOLD
end

.record(word) ⇒ Object



15
16
17
18
19
# File 'lib/lexdrill/stats.rb', line 15

def self.record(word)
  data = load
  data[word] = data.fetch(word, 0) + 1
  save(data)
end