class Corundum::QA::ReportFormatter

Adopted gratefully from Xavier Shay's Cane

Attributes

reports[R]

Public Class Methods

new(reports) click to toggle source
# File lib/corundum/qa-report.rb, line 7
def initialize(reports)
  @reports = reports
end

Public Instance Methods

to_s() click to toggle source
# File lib/corundum/qa-report.rb, line 12
def to_s
  return "" if reports.empty?

  widths = column_widths(reports)

  reports.map do |report|
    report.to_s(widths)
  end.join("\n") + "\n\n" + totals + "\n\n"
end

Protected Instance Methods

column_widths(reports) click to toggle source
# File lib/corundum/qa-report.rb, line 30
def column_widths(reports)
  Hash[[:file_and_line, :label, :value].map do |name|
    [name, max_width(name, &name)]
  end]
end
max_width(name) { |reject| ... } click to toggle source
# File lib/corundum/qa-report.rb, line 24
def max_width(name, &block)
  reports.map(&:rejects).flatten.map do |reject|
    yield(reject).to_s.length
  end.max
end
totals() click to toggle source
# File lib/corundum/qa-report.rb, line 36
def totals
  "Total QA report items: #{reports.inject(0){|sum, report| sum + report.length}}"
  "Total QA failing reports: #{reports.inject(0){|sum, report| sum + (report.passed ? 0 : 1)}}"
end