Sha256: 77192598cb2351e8856cc02da2164010fa5a19a611fb8a45ef13ea4cf1284f8c

Contents?: true

Size: 994 Bytes

Versions: 7

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

module ActiveRecall
  class Item < ActiveRecord::Base
    self.table_name = 'active_recall_items'

    belongs_to :deck

    scope :failed, -> { where(['box = ? and last_reviewed is not null', 0]) }
    scope :untested, -> { where(['box = ? and last_reviewed is null', 0]) }

    def self.expired(current_time: Time.current)
      where(['box > ? and next_review <= ?', 0, current_time])
    end

    def self.known(current_time: Time.current)
      where(['box > ? and next_review > ?', 0, current_time])
    end

    def source
      source_type.constantize.find(source_id)
    end

    def right!
      update!(algorithm_class.right(**scoring_attributes))
    end

    def wrong!
      update!(algorithm_class.wrong(**scoring_attributes))
    end

    private

    def algorithm_class
      ActiveRecall.configuration.algorithm_class
    end

    def scoring_attributes
      attributes.symbolize_keys.slice(:box, :times_right, :times_wrong)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_recall-1.6.4 lib/active_recall/models/item.rb
active_recall-1.6.3 lib/active_recall/models/item.rb
active_recall-1.6.2 lib/active_recall/models/item.rb
active_recall-1.6.1 lib/active_recall/models/item.rb
active_recall-1.6.0 lib/active_recall/models/item.rb
active_recall-1.5.0 lib/active_recall/models/item.rb
active_recall-1.4.0 lib/active_recall/models/item.rb