Class: ActiveRecall::Item

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_recall/models/item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.expired(current_time: Time.current) ⇒ Object



18
19
20
# File 'lib/active_recall/models/item.rb', line 18

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

.failed(current_time: Time.current) ⇒ Object

Lapsed (box 0, already reviewed) cards that are due now. A null next_review means “review immediately” (binary algorithms reset this way); a future next_review (e.g. SM-2’s one-day failure interval) is excluded until due.



14
15
16
# File 'lib/active_recall/models/item.rb', line 14

def self.failed(current_time: Time.current)
  where(["box = ? and last_reviewed is not null and (next_review is null or next_review <= ?)", 0, current_time])
end

.known(current_time: Time.current) ⇒ Object



22
23
24
# File 'lib/active_recall/models/item.rb', line 22

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

Instance Method Details

#right!Object



40
41
42
43
44
45
46
# File 'lib/active_recall/models/item.rb', line 40

def right!
  if algorithm_class.type == :binary
    update!(algorithm_class.right(**scoring_attributes))
  else
    raise IncompatibleAlgorithmError, "#{algorithm_class.name} is not a binary algorithm, so is not compatible with the #right! method"
  end
end

#score!(grade) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/active_recall/models/item.rb', line 26

def score!(grade)
  if algorithm_class.type == :gradable
    update!(
      algorithm_class.score(**scoring_attributes.merge(grade: grade))
    )
  else
    raise IncompatibleAlgorithmError, "#{algorithm_class.name} is a not an gradable algorithm, so is not compatible with the #score! method"
  end
end

#sourceObject



36
37
38
# File 'lib/active_recall/models/item.rb', line 36

def source
  source_type.constantize.find(source_id)
end

#wrong!Object



48
49
50
51
52
53
54
# File 'lib/active_recall/models/item.rb', line 48

def wrong!
  if algorithm_class.type == :binary
    update!(algorithm_class.wrong(**scoring_attributes))
  else
    raise IncompatibleAlgorithmError, "#{algorithm_class.name} is not a binary algorithm, so is not compatible with the #wrong! method"
  end
end