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 collapse
-
#start ⇒ String
A string representation of the record's (last) start time.
-
#status ⇒ String
The todo record's status (one of "started", "suspended", or "complete").
-
#stop ⇒ String
A string representation of the record's (last) stop time.
-
#todo ⇒ String
The todo message.
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.
- #populate_internal_fields ⇒ void
-
#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, #data_fields, #defer_sync, #external_fields, external_fields, gen_methods, #initialize, #initialize_from_hash, internal?, #internal?, load!, sensitive?, #sensitive?, #sync!, #to_h, #to_s, type
Constructor Details
This class inherits a constructor from KBSecret::Record::Abstract
Instance Attribute Details
#start ⇒ String
This is an internal field.
Returns a string representation of the record's (last) start time.
30 |
# File 'lib/kbsecret/record/todo.rb', line 30 data_field :todo, sensitive: false |
#status ⇒ String
This is an internal field.
Returns the todo record's status (one of "started", "suspended", or "complete").
30 |
# File 'lib/kbsecret/record/todo.rb', line 30 data_field :todo, sensitive: false |
#stop ⇒ String
This is an internal field.
Returns a string representation of the record's (last) stop time.
30 |
# File 'lib/kbsecret/record/todo.rb', line 30 data_field :todo, sensitive: false |
#todo ⇒ String
Returns the todo message.
30 |
# File 'lib/kbsecret/record/todo.rb', line 30 data_field :todo, sensitive: false |
Instance Method Details
#complete! ⇒ void
Does nothing if the item is already completed.
This method returns an undefined value.
Complete the to do item.
82 83 84 85 86 |
# File 'lib/kbsecret/record/todo.rb', line 82 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.
56 57 58 |
# File 'lib/kbsecret/record/todo.rb', line 56 def completed? !(started? || suspended?) end |
#populate_internal_fields ⇒ void
This method returns an undefined value.
37 38 39 40 41 42 43 |
# File 'lib/kbsecret/record/todo.rb', line 37 def populate_internal_fields defer_sync implicit: false do self.status = "suspended" self.start = nil self.stop = nil end end |
#start! ⇒ void
Does nothing if the item is already started.
This method returns an undefined value.
Start the to do item.
63 64 65 66 67 68 |
# File 'lib/kbsecret/record/todo.rb', line 63 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.
46 47 48 |
# File 'lib/kbsecret/record/todo.rb', line 46 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.
73 74 75 76 77 |
# File 'lib/kbsecret/record/todo.rb', line 73 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.
51 52 53 |
# File 'lib/kbsecret/record/todo.rb', line 51 def suspended? status == "suspended" end |