class Engine::CardState
CardStates form a linked list, each pointing to the previous state plus the new data point. The actual factor/interval, streak are calculated recursively based on the previous value, and the new data point.
Constants
- EMPTY
- START
- STRATEGY
Public Instance Methods
<<(data_point)
click to toggle source
# File lib/engine/card_state.rb, line 17 def << data_point self.class.new(self, data_point) end
data_points() { |data_point| ... }
click to toggle source
# File lib/engine/card_state.rb, line 29 def data_points(&blk) return to_enum(__method__) unless block_given? unless empty? parent.data_points(&blk) yield data_point end end
empty?()
click to toggle source
# File lib/engine/card_state.rb, line 25 def empty? parent.nil? end
expired?(time)
click to toggle source
# File lib/engine/card_state.rb, line 41 def expired?(time) (!empty? && data_point.fail?) || expired_for_seconds(time) > 0 end
expired_for_seconds(time)
click to toggle source
# File lib/engine/card_state.rb, line 45 def expired_for_seconds(time) empty? ? 0 : [time - last_shown - interval * 60, 0].max end
factor()
click to toggle source
# File lib/engine/card_state.rb, line 51 def factor ; empty? ? START[:factor] : strategy.next_factor end
inspect()
click to toggle source
# File lib/engine/card_state.rb, line 54 def inspect "<#{self.class} iteration: %d, streak: %d, factor: %.2f, interval: %.2f>" % [iteration, streak, factor, interval] end
interval()
click to toggle source
# File lib/engine/card_state.rb, line 52 def interval ; empty? ? START[:interval] : strategy.next_interval end
iteration()
click to toggle source
# File lib/engine/card_state.rb, line 49 def iteration ; empty? ? START[:iteration] : parent.iteration + 1 end
last_shown()
click to toggle source
# File lib/engine/card_state.rb, line 37 def last_shown data_points.to_a.last.timestamp end
strategy()
click to toggle source
# File lib/engine/card_state.rb, line 21 def strategy STRATEGY.new(parent, data_point) end
streak()
click to toggle source
# File lib/engine/card_state.rb, line 50 def streak ; empty? ? START[:streak] : strategy.next_streak end