class Diecut::Report

Attributes

advice[RW]
column_headers[R]
name[R]
passed[RW]
rejects[R]
status[RW]
summary[RW]
summary_count[RW]

Public Class Methods

new(name, column_headers) click to toggle source
# File lib/diecut/report.rb, line 86
def initialize(name, column_headers)
  @name = name
  @column_headers = column_headers
  @rejects = []
  @status = "OK"
  @passed = true
  @summary = ""
  @summary_counts = true
end

Public Instance Methods

add(*args) click to toggle source
# File lib/diecut/report.rb, line 98
def add(*args)
  @rejects << args
end
column_widths() click to toggle source
# File lib/diecut/report.rb, line 117
def column_widths
  column_headers.map.with_index do |header, idx|
    (@rejects.map{|reject| reject[idx]} + [header]).map{|field|
      field.to_s.length
    }.max
  end
end
context() click to toggle source
# File lib/diecut/report.rb, line 129
def context
  widths = column_widths
  {
    empty: empty?,
    passing: passed,
    status: status,
    name: name,
    length: summary_count,
    summary: summary,
    advice: advice,
    headers: sized(column_headers, widths),
    rejects: rejects.map do |reject|
      {reject: sized(reject, widths)}
    end
  }
end
count()
Alias for: length
empty?() click to toggle source
# File lib/diecut/report.rb, line 113
def empty?
  @rejects.empty?
end
fail(summary) click to toggle source
# File lib/diecut/report.rb, line 102
def fail(summary)
  @passed = false
  @status = "FAIL"
  @summary = summary
end
length() click to toggle source
# File lib/diecut/report.rb, line 108
def length
  @rejects.length
end
Also aliased as: count
sized(array, widths) click to toggle source
# File lib/diecut/report.rb, line 125
def sized(array, widths)
  array.take(widths.length).zip(widths).map{|item, width| { it: item.to_s.ljust(width)}}
end