Class: Herodot::Output

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

Constant Summary collapse

HEADERS =
%w[Project Branch Time].freeze
EMPTY_WORKLOG_MESSAGE =
Rainbow('Not enough entries in the worklog.').red +
' On a tracked repository `git checkout`'\
' and `git commit` will add entries.'.freeze
COLORS =
%i[green yellow blue magenta cyan aqua silver aliceblue indianred].freeze

Class Method Summary collapse

Class Method Details

.convert_format(worklogs_totals_per_day, format) ⇒ Object



26
27
28
29
30
31
# File 'lib/herodot/output.rb', line 26

def convert_format(worklogs_totals_per_day, format)
  case format
  when 'json'
    worklogs_totals_per_day.to_json
  end
end

.format_time(time_is_seconds) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/herodot/output.rb', line 13

def format_time(time_is_seconds)
  total_seconds = time_is_seconds.to_i
  seconds = total_seconds % 60
  minutes = (total_seconds / 60) % 60
  hours = total_seconds / (60 * 60)
  "#{hours}:#{minutes.to_s.rjust(2, '0')}:#{seconds.to_s.rjust(2, '0')}"
end


21
22
23
24
# File 'lib/herodot/output.rb', line 21

def print(worklogs_totals_per_day, opts)
  return convert_format(worklogs_totals_per_day, opts.format) if opts.format
  print_table(worklogs_totals_per_day)
end


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

def print_table(worklogs_totals_per_day)
  abort EMPTY_WORKLOG_MESSAGE if worklogs_totals_per_day.empty?
  Terminal::Table.new(headings: HEADERS) do |table|
    worklogs_totals_per_day.each do |date, times|
      table.add_separator
      table << [date]
      table.add_separator
      print_day(times).each { |row| table << row }
      table.add_separator
    end
  end
end