Class: TaskFormatter
- Inherits:
-
Object
- Object
- TaskFormatter
- Defined in:
- lib/task_formatter.rb
Instance Attribute Summary collapse
-
#bar_size ⇒ Object
Returns the value of attribute bar_size.
-
#max_width ⇒ Object
Returns the value of attribute max_width.
Class Method Summary collapse
Instance Method Summary collapse
- #extract_jt(name) ⇒ Object
- #format(task, task_len) ⇒ Object
-
#initialize(bar_size = 40, max_width = 94) ⇒ TaskFormatter
constructor
A new instance of TaskFormatter.
- #line_for_email ⇒ Object
- #line_for_interactive ⇒ Object
- #sync_status ⇒ Object
- #time_bar(full_char = '=', empty_char = ' ', ellipsis = '...') ⇒ Object
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( = 40, max_width = 94) @bar_size = @max_width = max_width @task = nil end |
Instance Attribute Details
#bar_size ⇒ Object
Returns the value of attribute bar_size.
3 4 5 |
# File 'lib/task_formatter.rb', line 3 def @bar_size end |
#max_width ⇒ Object
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_email ⇒ Object
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}" : '' " #{('#', ' ', '..')} #{@task.duration_formatted} #{task_formatted} #{jira_link}" end |
#line_for_interactive ⇒ Object
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} #{}" end |
#sync_status ⇒ Object
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 (full_char = '=', empty_char = ' ', ellipsis = '...') time_len = [@task.duration / 300, ].min if time_len >= "[#{(full_char * (time_len - 2)) + ellipsis}" else "[#{full_char * time_len}#{empty_char * ( - time_len)}]" end end |