Class: Task
- Inherits:
-
Object
- Object
- Task
- Defined in:
- lib/doneski/task.rb
Constant Summary collapse
- STATUS =
{new: 1, started: 5, complete: 2}
Instance Attribute Summary collapse
-
#date_created ⇒ Object
Returns the value of attribute date_created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#stage ⇒ Object
Returns the value of attribute stage.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #complete ⇒ Object
-
#initialize(options) ⇒ Task
constructor
A new instance of Task.
- #match(options) ⇒ Object
- #priority ⇒ Object
- #priority=(priority) ⇒ Object
- #start ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options) ⇒ Task
Returns a new instance of Task.
7 8 9 10 11 12 13 |
# File 'lib/doneski/task.rb', line 7 def initialize() @id = ['id'] || (0...4).map { ('a'..'z').to_a[rand(26)] }.join @title = ['title'] @stage = ['stage'] || STATUS[:new] @date_created = ['date_created'] || Time.now @priority = ['priority'] || '' end |
Instance Attribute Details
#date_created ⇒ Object
Returns the value of attribute date_created.
3 4 5 |
# File 'lib/doneski/task.rb', line 3 def date_created @date_created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/doneski/task.rb', line 2 def id @id end |
#stage ⇒ Object
Returns the value of attribute stage.
3 4 5 |
# File 'lib/doneski/task.rb', line 3 def stage @stage end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/doneski/task.rb', line 3 def title @title end |
Instance Method Details
#complete ⇒ Object
15 16 17 |
# File 'lib/doneski/task.rb', line 15 def complete @stage = STATUS[:complete] end |
#match(options) ⇒ Object
35 36 37 38 |
# File 'lib/doneski/task.rb', line 35 def match() .each{|key, value| return true if self.send(key) == value} false end |
#priority ⇒ Object
19 20 21 |
# File 'lib/doneski/task.rb', line 19 def priority !@priority.nil? ? -@priority.length : nil end |
#priority=(priority) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/doneski/task.rb', line 23 def priority=(priority) if priority.nil? @priority = '' else @priority = priority.match(/\+{1,}/)[0] unless priority.nil? end end |
#start ⇒ Object
31 32 33 |
# File 'lib/doneski/task.rb', line 31 def start @stage = STATUS[:started] end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/doneski/task.rb', line 40 def to_s "| \e[0;3#{stage.to_s}m#{id.to_s.ljust(8)}#{title.ljust(80)[0...80]}#{date_created.to_s.ljust(30)}#{@priority.ljust(10)}\e[0m |" end |