Class: TasksCLI::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Task

Returns a new instance of Task.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tasks_cli/task.rb', line 7

def initialize(row)
  @epic = extract_value(row[0])
  @number = extract_value(row[1])
  @name = extract_value(row[2])
  @description = extract_value(row[3])
  @priority = extract_value(row[4])
  @status = extract_value(row[5])
  @relates_to = extract_value(row[6])
  @blocked_by = extract_value(row[7])
  @updated_at = extract_value(row[8]) || Time.now.iso8601
end

Instance Attribute Details

#blocked_byObject (readonly)

Returns the value of attribute blocked_by.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def blocked_by
  @blocked_by
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def description
  @description
end

#epicObject (readonly)

Returns the value of attribute epic.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def epic
  @epic
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def number
  @number
end

#priorityObject (readonly)

Returns the value of attribute priority.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def priority
  @priority
end

#relates_toObject (readonly)

Returns the value of attribute relates_to.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def relates_to
  @relates_to
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def status
  @status
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



5
6
7
# File 'lib/tasks_cli/task.rb', line 5

def updated_at
  @updated_at
end

Instance Method Details

#detailed_viewObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tasks_cli/task.rb', line 28

def detailed_view
  "    \#{Rainbow(\"Epic:\").bright} \#{@epic}\n    \#{Rainbow(\"Number:\").bright} \#{Rainbow(@number).cyan}\n    \#{Rainbow(\"Name:\").bright} \#{Rainbow(@name).bright}\n    \#{Rainbow(\"Description:\").bright} \#{@description}\n    \#{Rainbow(\"Priority:\").bright} \#{priority_colored}\n    \#{Rainbow(\"Status:\").bright} \#{status_colored}\n    \#{Rainbow(\"Relates To:\").bright} \#{@relates_to}\n    \#{Rainbow(\"Blocked By:\").bright} \#{@blocked_by}\n    \#{Rainbow(\"Last Updated:\").bright} \#{@updated_at}\n  TASK\nend\n"

#extract_value(field) ⇒ Object



19
20
21
22
# File 'lib/tasks_cli/task.rb', line 19

def extract_value(field)
  return field if field.is_a?(String)
  field.is_a?(Array) ? field[1].to_s.strip : field.to_s.strip
end

#matches?(field, value) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/tasks_cli/task.rb', line 46

def matches?(field, value)
  send(field.to_sym).to_s.downcase.include?(value.to_s.downcase)
rescue NoMethodError
  false
end

#priority_coloredObject



65
66
67
68
69
70
71
72
# File 'lib/tasks_cli/task.rb', line 65

def priority_colored
  case @priority.downcase
  when 'high' then Rainbow(@priority).red
  when 'medium' then Rainbow(@priority).yellow
  when 'low' then Rainbow(@priority).green
  else Rainbow(@priority).white
  end
end

#status_coloredObject



56
57
58
59
60
61
62
63
# File 'lib/tasks_cli/task.rb', line 56

def status_colored
  case @status.downcase
  when 'to do' then Rainbow(@status).red
  when 'in progress' then Rainbow(@status).yellow
  when 'done' then Rainbow(@status).green
  else Rainbow(@status).white
  end
end

#to_csvObject



42
43
44
# File 'lib/tasks_cli/task.rb', line 42

def to_csv
  [@epic, @number, @name, @description, @priority, @status, @relates_to, @blocked_by, @updated_at]
end

#to_sObject



24
25
26
# File 'lib/tasks_cli/task.rb', line 24

def to_s
  "#{Rainbow(@number).cyan}: #{Rainbow(@name).bright} (#{status_colored}) - Priority: #{priority_colored} - Updated: #{@updated_at}"
end

#update_timestampObject



52
53
54
# File 'lib/tasks_cli/task.rb', line 52

def update_timestamp
  @updated_at = Time.now.iso8601
end