Class: KBSecret::Record::Todo

Inherits:
Abstract
  • Object
show all
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

Attributes inherited from Abstract

#data, #label, #path, #session, #timestamp, #type

Instance Method Summary collapse

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

#startString

Note:

This is an internal field.

Returns a string representation of the record's (last) start time.

Returns:

  • (String)

    a string representation of the record's (last) start time



30
# File 'lib/kbsecret/record/todo.rb', line 30

data_field :todo, sensitive: false

#statusString

Note:

This is an internal field.

Returns the todo record's status (one of "started", "suspended", or "complete").

Returns:

  • (String)

    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

#stopString

Note:

This is an internal field.

Returns a string representation of the record's (last) stop time.

Returns:

  • (String)

    a string representation of the record's (last) stop time



30
# File 'lib/kbsecret/record/todo.rb', line 30

data_field :todo, sensitive: false

#todoString

Returns the todo message.

Returns:

  • (String)

    the todo message



30
# File 'lib/kbsecret/record/todo.rb', line 30

data_field :todo, sensitive: false

Instance Method Details

#complete!void

Note:

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.

Returns:

  • (Boolean)

    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_fieldsvoid

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

Note:

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.

Returns:

  • (Boolean)

    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

Note:

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.

Returns:

  • (Boolean)

    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