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.



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

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.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def blocked_by
  @blocked_by
end

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def description
  @description
end

#epicObject (readonly)

Returns the value of attribute epic.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def epic
  @epic
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def number
  @number
end

#priorityObject (readonly)

Returns the value of attribute priority.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def priority
  @priority
end

#relates_toObject (readonly)

Returns the value of attribute relates_to.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def relates_to
  @relates_to
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def status
  @status
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



7
8
9
# File 'lib/tasks_cli/task.rb', line 7

def updated_at
  @updated_at
end

Instance Method Details

#detailed_viewObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tasks_cli/task.rb', line 32

def detailed_view
  <<~TASK
    #{Rainbow('Epic:').bright} #{@epic}
    #{Rainbow('Number:').bright} #{Rainbow(@number).cyan}
    #{Rainbow('Name:').bright} #{Rainbow(@name).bright}
    #{Rainbow('Description:').bright} #{@description}
    #{Rainbow('Priority:').bright} #{priority_colored}
    #{Rainbow('Status:').bright} #{status_color}
    #{Rainbow('Relates To:').bright} #{@relates_to}
    #{Rainbow('Blocked By:').bright} #{@blocked_by}
    #{Rainbow('Last Updated:').bright} #{@updated_at}
  TASK
end

#extract_value(field) ⇒ Object



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

def extract_value(field)
  return '' if field.nil?
  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)


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

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

#priority_coloredObject



69
70
71
72
73
74
75
76
# File 'lib/tasks_cli/task.rb', line 69

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_colorObject



60
61
62
63
64
65
66
67
# File 'lib/tasks_cli/task.rb', line 60

def status_color
  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



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

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

#to_sObject



28
29
30
# File 'lib/tasks_cli/task.rb', line 28

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

#update_timestampObject



56
57
58
# File 'lib/tasks_cli/task.rb', line 56

def update_timestamp
  @updated_at = Time.now.iso8601
end