Class: Reminder
- Inherits:
-
Object
- Object
- Reminder
- Defined in:
- lib/forgetful/reminder.rb,
lib/forgetful/extensions/csv/reminder.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#due_on ⇒ Object
readonly
Returns the value of attribute due_on.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #ef ⇒ Object
-
#initialize(question, answer, due_on = Date.today, history = []) ⇒ Reminder
constructor
A new instance of Reminder.
- #next(q) ⇒ Object
- #review? ⇒ Boolean
- #to_a ⇒ Object
- #to_csv ⇒ Object
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
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
2 3 4 |
# File 'lib/forgetful/reminder.rb', line 2 def answer @answer end |
#due_on ⇒ Object (readonly)
Returns the value of attribute due_on.
2 3 4 |
# File 'lib/forgetful/reminder.rb', line 2 def due_on @due_on end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
2 3 4 |
# File 'lib/forgetful/reminder.rb', line 2 def history @history end |
#question ⇒ Object (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 |
#ef ⇒ Object
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
28 29 30 |
# File 'lib/forgetful/reminder.rb', line 28 def review? history.empty? || history.last < 4 end |
#to_a ⇒ Object
20 21 22 |
# File 'lib/forgetful/reminder.rb', line 20 def to_a [question, answer, due_on, history] end |
#to_csv ⇒ Object
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 |