Sha256: 54fb1fd805faff037dd0df7f5a23bc104f50b0211543a1f231aa29bb80682e1e

Contents?: true

Size: 1.35 KB

Versions: 12

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module ActiveRecall
  class LeitnerSystem
    DELAYS = [3, 7, 14, 30, 60, 120, 240].freeze

    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

    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

    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

    def right
      {
        box: box + 1,
        times_right: times_right + 1,
        times_wrong: times_wrong,
        last_reviewed: current_time,
        next_review: next_review
      }
    end

    def wrong
      {
        box: 0,
        times_right: times_right,
        times_wrong: times_wrong + 1,
        last_reviewed: current_time,
        next_review: nil
      }
    end

    private

    attr_reader :box, :current_time, :times_right, :times_wrong

    def next_review
      (current_time + DELAYS[[DELAYS.count, box + 1].min - 1].days)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
active_recall-1.8.6 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.8.5 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.8.4 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.8.3 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.8.0 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.6.4 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.6.3 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.6.2 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.6.1 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.6.0 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.5.0 lib/active_recall/algorithms/leitner_system.rb
active_recall-1.4.0 lib/active_recall/algorithms/leitner_system.rb