class XcMetricsAggregator::CSVFormatter
Public Instance Methods
format_chart(data)
click to toggle source
# File lib/xc_metrics_aggregator/formatter/formatter.rb, line 64 def format_chart(data) csv_head = data.series.headings + ["Point"] output = csv_head.join(',') + "\n" rows = data.series.rows.map do |line| label = line.first unless label next end sample = data.samples.find {|sample| sample.first == label } unless sample next end line.append(sample.last) end output += rows.map do |row| row.map{ |e| e.to_s.include?(",") ? "\"#{e}\"" : e } .join(',') end .join("\n") output += "\n" output end
format_table(data)
click to toggle source
# File lib/xc_metrics_aggregator/formatter/formatter.rb, line 34 def format_table(data) output = data.headings.join(',') + "\n" data.rows.each do |row| if row == :separator next end sub_rows = row.map { |e| e.split("\n") } max_sub_row = sub_rows.max { |a, b| a.count <=> b.count } expaneded_sub_rows = sub_rows.map do |sub_row| unit = max_sub_row.count / sub_row.count mod = max_sub_row.count.modulo sub_row.count expanded_sub_row = sub_row.map { |sub_row_e| Array.new(unit, sub_row_e) }.flatten if sub_row.last expanded_sub_row += Array.new(mod, sub_row.last) end expanded_sub_row end output += expaneded_sub_rows .transpose .map do |row| row.map{ |e| e.include?(",") ? "\"#{e}\"" : e } .join(',') end .join("\n") output += "\n" end output end