1 # frozen_string_literal: true
10 def run(base_path:, prefix:)
14 Dir["#{base_path}/#{prefix}*"].each do |filename|
15 totals = add_month(totals: totals, filename: filename)
19 routes = totals.keys.reject{|x| x.is_a? Symbol}.sort_by(&:to_i)
20 headers.append(routes)
22 puts headers.join(";")
23 @monthly_totals.keys.sort_by(&:to_i).each do |month|
24 values = @monthly_totals[month]
26 "#{values[:year]}-#{values[:month]}",
27 routes.map{|route| values[route] || ""},
33 routes.map{|route| totals[route] || ""},
39 def add_month(totals:, filename:)
40 current_month = parse_month(filename: filename)
42 current_month.each do |key, count|
43 sum = totals[key] || 0
48 @monthly_totals[current_month[:month]] = current_month
53 def parse_month(filename:)
55 File.open(filename, "r") do |fd|
56 fd.readlines.each do |line|
57 tokens = line.split(";")
58 next unless 3 == tokens.count
60 date, total, spec = line.split(";")
62 year, month = date.split("-")
63 totals[:year] ||= year
64 totals[:month] ||= month
66 sum = totals[:sum] || 0
70 hash.each do |route, count|
71 sum = totals[route] || 0