Class: TaskFormatter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bar_size = 40, max_width = 94) ⇒ TaskFormatter

Returns a new instance of TaskFormatter.



5
6
7
8
9
# File 'lib/task_formatter.rb', line 5

def initialize(bar_size = 40, max_width = 94)
  @bar_size = bar_size
  @max_width = max_width
  @task = nil
end

Instance Attribute Details

#bar_sizeObject

Returns the value of attribute bar_size.



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

def bar_size
  @bar_size
end

#max_widthObject

Returns the value of attribute max_width.



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

def max_width
  @max_width
end

Class Method Details

.max_length(tasks) ⇒ Object



17
18
19
# File 'lib/task_formatter.rb', line 17

def self.max_length(tasks)
  [tasks.map { |e| e.name.length }.max || 0, 60].min
end

Instance Method Details

#extract_jt(name) ⇒ Object



39
40
41
42
# File 'lib/task_formatter.rb', line 39

def extract_jt(name)
  match = name[/^jt-[0-9]+/]
  match ? match.upcase : nil
end

#format(task, task_len) ⇒ Object



11
12
13
14
15
# File 'lib/task_formatter.rb', line 11

def format(task, task_len)
  @task = task
  @task_len = task_len
  self
end

#line_for_emailObject



44
45
46
47
48
49
# File 'lib/task_formatter.rb', line 44

def line_for_email
  task_formatted = @task.name[0, @task_len]
  jt = extract_jt(@task.name)
  jira_link = jt ? "https://jobteaser.atlassian.net/browse/#{jt}" : ''
  "  #{time_bar('#', '  ', '..')} #{@task.duration_formatted}  #{task_formatted} #{jira_link}"
end

#line_for_interactiveObject



34
35
36
37
# File 'lib/task_formatter.rb', line 34

def line_for_interactive
  task_formatted = @task.name[0, @task_len].ljust(@task_len, ' ')
  "  #{task_formatted} #{@task.duration_formatted}  #{time_bar}"
end

#sync_statusObject



30
31
32
# File 'lib/task_formatter.rb', line 30

def sync_status
  !!@task.synced_at ? '' : ''
end

#time_bar(full_char = '=', empty_char = ' ', ellipsis = '...') ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/task_formatter.rb', line 21

def time_bar(full_char = '=', empty_char = ' ', ellipsis = '...')
  time_len = [@task.duration / 300, bar_size].min
  if time_len >= bar_size
    "[#{(full_char * (time_len - 2)) + ellipsis}"
  else
    "[#{full_char * time_len}#{empty_char * (bar_size - time_len)}]"
  end
end