Class: Reminder

Inherits:
Object
  • Object
show all
Defined in:
lib/forgetful/reminder.rb,
lib/forgetful/extensions/csv/reminder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(question, answer, due_on = Date.today, history = []) ⇒ Reminder

Returns a new instance of Reminder.



4
5
6
7
8
9
# File 'lib/forgetful/reminder.rb', line 4

def initialize(question, answer, due_on=Date.today, history=[])
  @question = question
  @answer = answer
  @due_on = due_on
  @history = history.dup.freeze
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



2
3
4
# File 'lib/forgetful/reminder.rb', line 2

def answer
  @answer
end

#due_onObject (readonly)

Returns the value of attribute due_on.



2
3
4
# File 'lib/forgetful/reminder.rb', line 2

def due_on
  @due_on
end

#historyObject (readonly)

Returns the value of attribute history.



2
3
4
# File 'lib/forgetful/reminder.rb', line 2

def history
  @history
end

#questionObject (readonly)

Returns the value of attribute question.



2
3
4
# File 'lib/forgetful/reminder.rb', line 2

def question
  @question
end

Instance Method Details

#<=>(other) ⇒ Object



24
25
26
# File 'lib/forgetful/reminder.rb', line 24

def <=>(other)
  to_a <=> other.to_a
end

#efObject



11
12
13
# File 'lib/forgetful/reminder.rb', line 11

def ef
  SuperMemo::traverse(history)[0]
end

#next(q) ⇒ Object



15
16
17
18
# File 'lib/forgetful/reminder.rb', line 15

def next(q)
  new_history = history + [q]
  Reminder.new(question, answer, SuperMemo::next_date(Date.today, new_history), new_history)
end

#review?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/forgetful/reminder.rb', line 28

def review?
  history.empty? || history.last < 4
end

#to_aObject



20
21
22
# File 'lib/forgetful/reminder.rb', line 20

def to_a
  [question, answer, due_on, history]
end

#to_csvObject



10
11
12
13
14
15
16
# File 'lib/forgetful/extensions/csv/reminder.rb', line 10

def to_csv
  if history.empty?
    [question, answer, due_on.to_s]
  else
    [question, answer, due_on.to_s, history.join]
  end
end