class Herodot::Output
Constants
- COLORS
- EMPTY_WORKLOG_MESSAGE
- HEADERS
Public Class Methods
convert_format(worklogs_totals_per_day, format)
click to toggle source
# 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)
click to toggle source
# 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
print(worklogs_totals_per_day, opts)
click to toggle source
# 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
print_table(worklogs_totals_per_day)
click to toggle source
# 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
Private Class Methods
colorize(project)
click to toggle source
# File lib/herodot/output.rb, line 48 def colorize(project) Rainbow(project).color(COLORS[project.chars.map(&:ord).reduce(:+) % COLORS.size]) end
print_day(times)
click to toggle source
# File lib/herodot/output.rb, line 56 def print_day(times) times_by_project_and_branch(times).flat_map do |log| lines = [[colorize(log[:project]), log[:branch], format_time(log[:time])]] lines << ['', Rainbow(log[:link]).color(80, 80, 80), ''] if log[:link] lines end end
times_by_project_and_branch(times)
click to toggle source
# File lib/herodot/output.rb, line 52 def times_by_project_and_branch(times) times.sort_by { |log| [log[:project], log[:branch]] } end