Class: KBSecret::Record::Todo
- Defined in:
- lib/kbsecret/record/todo.rb
Overview
Represents a record containing a 'to do' item and its status.
Apart from the text of the item itself, each record contains three relevant fields: the item's status, a start time, and a stop time.
The status is one of "started"
, "suspended"
, or "complete"
, each
of which should be self-explanatory.
The start time is the date and time at which the item was started via #start!.
The stop time is the date and time at which the item was either last suspended via #suspend! or finished via #complete!.
Instance Attribute Summary
Attributes inherited from Abstract
#data, #label, #path, #session, #timestamp, #type
Instance Method Summary collapse
-
#complete! ⇒ void
Complete the to do item.
-
#completed? ⇒ Boolean
Whether or not the item is marked as completed.
-
#initialize(session, label, todo) ⇒ Todo
constructor
A new instance of Todo.
-
#start! ⇒ void
Start the to do item.
-
#started? ⇒ Boolean
Whether or not the item is marked as started.
-
#suspend! ⇒ void
Suspend the to do item.
-
#suspended? ⇒ Boolean
Whether or not the item is marked as suspended.
Methods inherited from Abstract
data_field, data_fields, gen_methods, #initialize_from_hash, load!, #sync!, #to_h, #to_s, type
Constructor Details
#initialize(session, label, todo) ⇒ Todo
Returns a new instance of Todo.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kbsecret/record/todo.rb', line 25 def initialize(session, label, todo) super(session, label) @data = { todo: { todo: todo, status: "suspended", start: nil, stop: nil, }, } end |
Instance Method Details
#complete! ⇒ void
Does nothing if the item is already completed.
This method returns an undefined value.
Complete the to do item.
75 76 77 78 79 |
# File 'lib/kbsecret/record/todo.rb', line 75 def complete! return if completed? self.status = "complete" self.stop = Time.now.to_s end |
#completed? ⇒ Boolean
Returns whether or not the item is marked as completed.
49 50 51 |
# File 'lib/kbsecret/record/todo.rb', line 49 def completed? !(started? || suspended?) end |
#start! ⇒ void
Does nothing if the item is already started.
This method returns an undefined value.
Start the to do item.
56 57 58 59 60 61 |
# File 'lib/kbsecret/record/todo.rb', line 56 def start! return if started? self.status = "started" self.start = Time.now.to_s end |
#started? ⇒ Boolean
Returns whether or not the item is marked as started.
39 40 41 |
# File 'lib/kbsecret/record/todo.rb', line 39 def started? status == "started" end |
#suspend! ⇒ void
Does nothing if the item is already suspended.
This method returns an undefined value.
Suspend the to do item.
66 67 68 69 70 |
# File 'lib/kbsecret/record/todo.rb', line 66 def suspend! return if suspended? self.status = "suspended" self.stop = Time.now.to_s end |
#suspended? ⇒ Boolean
Returns whether or not the item is marked as suspended.
44 45 46 |
# File 'lib/kbsecret/record/todo.rb', line 44 def suspended? status == "suspended" end |