class BeetleETL::Reporter
Public Class Methods
new(config, report)
click to toggle source
# File lib/beetle_etl/reporter.rb, line 4 def initialize(config, report) @config = config @report = report end
Public Instance Methods
log_summary()
click to toggle source
# File lib/beetle_etl/reporter.rb, line 9 def log_summary @config.logger.info(summary) end
Private Instance Methods
format_duration(duration)
click to toggle source
# File lib/beetle_etl/reporter.rb, line 39 def format_duration(duration) Time.at(duration).utc.strftime("%H:%M:%S") end
line_width()
click to toggle source
# File lib/beetle_etl/reporter.rb, line 49 def line_width # 2 spaces # + 1 colon # + 1 space # + 8 duration 12 + longest_step_name_length end
longest_step_name_length()
click to toggle source
# File lib/beetle_etl/reporter.rb, line 57 def longest_step_name_length @report.keys.max_by(&:length).length - 1 end
seperator(character)
click to toggle source
# File lib/beetle_etl/reporter.rb, line 61 def seperator(character) character * line_width end
step_rows(steps)
click to toggle source
# File lib/beetle_etl/reporter.rb, line 29 def step_rows(steps) steps.map do |step_name, data| label = step_name.split(": ")[1] + ":" duration = format_duration(data[:finished_at] - data[:started_at]) line = duration.rjust(line_width) line[2, label.length] = label line end end
sum_durations(steps)
click to toggle source
# File lib/beetle_etl/reporter.rb, line 43 def sum_durations(steps) steps.inject(0) do |acc, (_step_name, data)| acc + (data[:finished_at] - data[:started_at]) end end
summary()
click to toggle source
# File lib/beetle_etl/reporter.rb, line 15 def summary "\n\n" + @report.map do |(table_name, steps)| total_duration = format_duration(sum_durations(steps)) [ table_name, seperator("="), step_rows(steps).join("\n"), seperator("-"), total_duration.rjust(line_width) ].join("\n") end.join("\n\n") + "\n" end