Module: SuperMemo::SM2
- Defined in:
- lib/spaced-repetition/sm2.rb
Overview
This module can be used as a mixin to add the algorithms as used by SuperMemo 2 (typically referred to as SM2).
See the README for more information.
Class Method Summary collapse
Instance Method Summary collapse
- #check_spaced_repetition_methods ⇒ Object
- #process_recall_result(quality_of_recall) ⇒ Object
- #reset_spaced_repetition_data ⇒ Object
- #scheduled_to_recall? ⇒ Boolean
Class Method Details
.extended(obj) ⇒ Object
9 10 11 |
# File 'lib/spaced-repetition/sm2.rb', line 9 def SM2.extended(obj) obj.check_spaced_repetition_methods end |
Instance Method Details
#check_spaced_repetition_methods ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/spaced-repetition/sm2.rb', line 52 def check_spaced_repetition_methods begin send(:easiness_factor) send(:number_repetitions) send(:quality_of_last_recall) send(:next_repetition) send(:repetition_interval) rescue NoMethodError => e DBC.assert(false, e.) end end |
#process_recall_result(quality_of_recall) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/spaced-repetition/sm2.rb', line 21 def process_recall_result(quality_of_recall) DBC.require(quality_of_recall >= 0) DBC.require(quality_of_recall <= 5) DBC.require(easiness_factor) DBC.require(number_repetitions) if quality_of_recall < 3 self.number_repetitions = 0 else self.number_repetitions += 1 self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall) end case number_repetitions when 0 self.repetition_interval = 0 when 1 self.repetition_interval = 1 when 2 self.repetition_interval = 6 else self.repetition_interval = repetition_interval * easiness_factor end self.next_repetition = Date.today + repetition_interval end |
#reset_spaced_repetition_data ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/spaced-repetition/sm2.rb', line 13 def reset_spaced_repetition_data self.easiness_factor = 2.5 self.number_repetitions = 0 self.quality_of_last_recall = nil self.repetition_interval = nil self.next_repetition = nil end |
#scheduled_to_recall? ⇒ Boolean
48 49 50 |
# File 'lib/spaced-repetition/sm2.rb', line 48 def scheduled_to_recall? !next_repetition.nil? && next_repetition <= Date.today end |