Class: Task

Inherits:
Object
  • Object
show all
Defined in:
lib/doneski/task.rb

Constant Summary collapse

STATUS =
{new: 1, started: 5, complete: 2}

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @id = options['id'] || (0...4).map { ('a'..'z').to_a[rand(26)] }.join
  @title = options['title']
  @stage = options['stage'] || STATUS[:new]
  @date_created = options['date_created'] || Time.now
  @priority = options['priority'] || ''
end

Instance Attribute Details

#date_createdObject

Returns the value of attribute date_created.



3
4
5
# File 'lib/doneski/task.rb', line 3

def date_created
  @date_created
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/doneski/task.rb', line 2

def id
  @id
end

#stageObject

Returns the value of attribute stage.



3
4
5
# File 'lib/doneski/task.rb', line 3

def stage
  @stage
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/doneski/task.rb', line 3

def title
  @title
end

Instance Method Details

#completeObject



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(options)
  options.each{|key, value| return true if self.send(key) == value}
  false
end

#priorityObject



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

#startObject



31
32
33
# File 'lib/doneski/task.rb', line 31

def start
  @stage = STATUS[:started]
end

#to_sObject



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