Class: Diecut::Report
- Inherits:
-
Object
- Object
- Diecut::Report
- Defined in:
- lib/diecut/report.rb
Instance Attribute Summary collapse
-
#advice ⇒ Object
Returns the value of attribute advice.
-
#column_headers ⇒ Object
readonly
Returns the value of attribute column_headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#passed ⇒ Object
Returns the value of attribute passed.
-
#rejects ⇒ Object
readonly
Returns the value of attribute rejects.
-
#status ⇒ Object
Returns the value of attribute status.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#summary_count ⇒ Object
Returns the value of attribute summary_count.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #column_widths ⇒ Object
- #context ⇒ Object
- #empty? ⇒ Boolean
- #fail(summary) ⇒ Object
-
#initialize(name, column_headers) ⇒ Report
constructor
A new instance of Report.
- #length ⇒ Object (also: #count)
- #sized(array, widths) ⇒ Object
Constructor Details
#initialize(name, column_headers) ⇒ Report
Returns a new instance of Report.
86 87 88 89 90 91 92 93 94 |
# 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 |
Instance Attribute Details
#advice ⇒ Object
Returns the value of attribute advice.
96 97 98 |
# File 'lib/diecut/report.rb', line 96 def advice @advice end |
#column_headers ⇒ Object (readonly)
Returns the value of attribute column_headers.
95 96 97 |
# File 'lib/diecut/report.rb', line 95 def column_headers @column_headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
95 96 97 |
# File 'lib/diecut/report.rb', line 95 def name @name end |
#passed ⇒ Object
Returns the value of attribute passed.
96 97 98 |
# File 'lib/diecut/report.rb', line 96 def passed @passed end |
#rejects ⇒ Object (readonly)
Returns the value of attribute rejects.
95 96 97 |
# File 'lib/diecut/report.rb', line 95 def rejects @rejects end |
#status ⇒ Object
Returns the value of attribute status.
96 97 98 |
# File 'lib/diecut/report.rb', line 96 def status @status end |
#summary ⇒ Object
Returns the value of attribute summary.
96 97 98 |
# File 'lib/diecut/report.rb', line 96 def summary @summary end |
#summary_count ⇒ Object
Returns the value of attribute summary_count.
96 97 98 |
# File 'lib/diecut/report.rb', line 96 def summary_count @summary_count end |
Instance Method Details
#add(*args) ⇒ Object
98 99 100 |
# File 'lib/diecut/report.rb', line 98 def add(*args) @rejects << args end |
#column_widths ⇒ Object
117 118 119 120 121 122 123 |
# 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 ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# 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 |
#empty? ⇒ Boolean
113 114 115 |
# File 'lib/diecut/report.rb', line 113 def empty? @rejects.empty? end |
#fail(summary) ⇒ Object
102 103 104 105 106 |
# File 'lib/diecut/report.rb', line 102 def fail(summary) @passed = false @status = "FAIL" @summary = summary end |
#length ⇒ Object Also known as: count
108 109 110 |
# File 'lib/diecut/report.rb', line 108 def length @rejects.length end |
#sized(array, widths) ⇒ Object
125 126 127 |
# 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 |