class ActiveRecall::FibonacciSequence
Constants
- SEQUENCE
Attributes
box[R]
current_time[R]
times_right[R]
times_wrong[R]
Public Class Methods
new(box:, times_right:, times_wrong:, current_time: Time.current)
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 23 def initialize(box:, times_right:, times_wrong:, current_time: Time.current) @box = box @current_time = current_time @times_right = times_right @times_wrong = times_wrong end
right(box:, times_right:, times_wrong:, current_time: Time.current)
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 5 def self.right(box:, times_right:, times_wrong:, current_time: Time.current) new( box: box, current_time: current_time, times_right: times_right, times_wrong: times_wrong ).right end
wrong(box:, times_right:, times_wrong:, current_time: Time.current)
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 14 def self.wrong(box:, times_right:, times_wrong:, current_time: Time.current) new( box: box, current_time: current_time, times_right: times_right, times_wrong: times_wrong ).wrong end
Public Instance Methods
right()
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 30 def right { box: box + 1, last_reviewed: current_time, next_review: next_review, times_right: times_right + 1, times_wrong: times_wrong } end
wrong()
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 40 def wrong { box: [0, box - 1].max, last_reviewed: current_time, next_review: nil, times_right: times_right, times_wrong: times_wrong + 1 } end
Private Instance Methods
fibonacci_number_at(index)
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 56 def fibonacci_number_at(index) if (0...SEQUENCE.length).cover?(index) SEQUENCE[index] else fibonacci_number_at(index - 1) + fibonacci_number_at(index - 2) end end
next_review()
click to toggle source
# File lib/active_recall/algorithms/fibonacci_sequence.rb, line 64 def next_review current_time + fibonacci_number_at(box + 1).days end