Class: ActiveRecall::SM2

Inherits:
Object
  • Object
show all
Defined in:
lib/active_recall/algorithms/sm2.rb

Constant Summary collapse

MIN_EASINESS_FACTOR =
1.3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current) ⇒ SM2

Returns a new instance of SM2.



26
27
28
29
30
31
32
33
34
# File 'lib/active_recall/algorithms/sm2.rb', line 26

def initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current)
  @box = box
  @easiness_factor = easiness_factor || 2.5
  @times_right = times_right
  @times_wrong = times_wrong
  @grade = grade
  @current_time = current_time
  @interval = [1, box].max
end

Class Method Details

.required_attributesObject



7
8
9
# File 'lib/active_recall/algorithms/sm2.rb', line 7

def self.required_attributes
  REQUIRED_ATTRIBUTES
end

.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/active_recall/algorithms/sm2.rb', line 11

def self.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current)
  new(
    box: box,
    easiness_factor: easiness_factor,
    times_right: times_right,
    times_wrong: times_wrong,
    grade: grade,
    current_time: current_time
  ).score
end

.typeObject



22
23
24
# File 'lib/active_recall/algorithms/sm2.rb', line 22

def self.type
  :gradable
end

Instance Method Details

#scoreObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_recall/algorithms/sm2.rb', line 36

def score
  raise "Grade must be between 0-5!" unless GRADES.include?(@grade)
  update_easiness_factor
  update_repetition_and_interval

  {
    box: @box,
    easiness_factor: @easiness_factor,
    times_right: @times_right,
    times_wrong: @times_wrong,
    last_reviewed: @current_time,
    next_review: next_review
  }
end