module ActsAsLearnable::InstanceMethods

Public Instance Methods

due_today?() click to toggle source
# File lib/acts_as_learnable/base.rb, line 39
def due_today?
  due.nil? || due <= Date.today
end
review(recall_quality) click to toggle source
# File lib/acts_as_learnable/base.rb, line 17
def review(recall_quality)
  fail unless (1..5).include?(recall_quality)

  # If the quality of response was lower than 3, then start repetitions from the beginning
  reset and return if recall_quality <= 2

  # Calculate new easiness factor
  update_easiness_factor(recall_quality)

  # Repeat all items that scored below 4
  if recall_quality == 3
    self.interval = 0
  else
    # Otherwise, increment repetitions count and set new interval
    self.repetitions += 1
    update_interval
  end

  schedule_repetition
  save
end

Private Instance Methods

calculate_easiness_factor(quality) click to toggle source

Calculates new easiness factor according to the formula

# File lib/acts_as_learnable/base.rb, line 62
def calculate_easiness_factor(quality)
  easiness_factor + (0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02))
end
reset() click to toggle source

Bad recall quality, start over

# File lib/acts_as_learnable/base.rb, line 46
def reset
  self.repetitions = 0
  self.interval = 0
  self.due = Date.today
  self.studied_at = Date.today
  save
end
schedule_repetition() click to toggle source

Update next repetition date, set studied_at to today

# File lib/acts_as_learnable/base.rb, line 79
def schedule_repetition
  self.due = Date.today + interval
  self.studied_at = Date.today
end
update_easiness_factor(quality) click to toggle source

Calculates and updates easiness factor

# File lib/acts_as_learnable/base.rb, line 55
def update_easiness_factor(quality)
  new_easiness_factor = calculate_easiness_factor(quality)
  # If EF is less than 1.3 then let EF be 1.3
  self.easiness_factor = new_easiness_factor < 1.3 ? 1.3 : new_easiness_factor
end
update_interval() click to toggle source

Update interval according to the formula

# File lib/acts_as_learnable/base.rb, line 67
def update_interval
  # TODO: Extract magic numbers
  self.interval =
    case repetitions
    when 1 then 1
    when 2 then 6
    else
      interval(repetitions - 1) * easiness_factor
    end
end