Class: Taskcmd::Task
- Inherits:
-
Object
- Object
- Taskcmd::Task
- Defined in:
- lib/taskcmd/task.rb
Overview
An individual Todo item
Constant Summary collapse
- PRIORITY_LOW =
:low- PRIORITY_MEDIUM =
:medium- PRIORITY_HIGH =
:high- PRIORITY_CHOICES =
[PRIORITY_LOW, PRIORITY_MEDIUM, PRIORITY_HIGH]
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#priority ⇒ Object
Returns the value of attribute priority.
Class Method Summary collapse
Instance Method Summary collapse
- #complete! ⇒ Object
- #done? ⇒ Boolean
-
#initialize(id) ⇒ Task
constructor
A new instance of Task.
- #to_msgpack_ext ⇒ Object
- #to_s ⇒ Object
- #undo! ⇒ Object
Constructor Details
#initialize(id) ⇒ Task
Returns a new instance of Task.
14 15 16 17 18 19 20 |
# File 'lib/taskcmd/task.rb', line 14 def initialize(id) raise Taskcmd::Error, 'invalid id' unless id.is_a?(Integer) @id = id @priority = PRIORITY_MEDIUM @created_at = Time.now end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
11 12 13 |
# File 'lib/taskcmd/task.rb', line 11 def completed_at @completed_at end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
11 12 13 |
# File 'lib/taskcmd/task.rb', line 11 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/taskcmd/task.rb', line 12 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/taskcmd/task.rb', line 11 def id @id end |
#priority ⇒ Object
Returns the value of attribute priority.
11 12 13 |
# File 'lib/taskcmd/task.rb', line 11 def priority @priority end |
Class Method Details
.from_msgpack_ext(data) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/taskcmd/task.rb', line 62 def self.from_msgpack_ext(data) unpacked = MessagePack.unpack(data) new(unpacked[:id]).tap do |obj| unpacked.each { |k, v| obj.instance_variable_set("@#{k}", v) } end end |
Instance Method Details
#complete! ⇒ Object
32 33 34 |
# File 'lib/taskcmd/task.rb', line 32 def complete! @completed_at = Time.now end |
#done? ⇒ Boolean
40 41 42 |
# File 'lib/taskcmd/task.rb', line 40 def done? !@completed_at.nil? end |
#to_msgpack_ext ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/taskcmd/task.rb', line 52 def to_msgpack_ext { id: id, priority: priority, description: description, created_at: created_at, completed_at: completed_at, }.to_msgpack end |
#to_s ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/taskcmd/task.rb', line 44 def to_s "id: #{id}\n" \ "priority: #{priority}\n" \ "description: #{description}\n" \ "created_at: #{created_at}\n" \ "completed_at: #{completed_at || "-"}" \ end |
#undo! ⇒ Object
36 37 38 |
# File 'lib/taskcmd/task.rb', line 36 def undo! @completed_at = nil end |