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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/diecut/report.rb', line 76 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.
86 87 88 |
# File 'lib/diecut/report.rb', line 86 def advice @advice end |
#column_headers ⇒ Object (readonly)
Returns the value of attribute column_headers.
85 86 87 |
# File 'lib/diecut/report.rb', line 85 def column_headers @column_headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
85 86 87 |
# File 'lib/diecut/report.rb', line 85 def name @name end |
#passed ⇒ Object
Returns the value of attribute passed.
86 87 88 |
# File 'lib/diecut/report.rb', line 86 def passed @passed end |
#rejects ⇒ Object (readonly)
Returns the value of attribute rejects.
85 86 87 |
# File 'lib/diecut/report.rb', line 85 def rejects @rejects end |
#status ⇒ Object
Returns the value of attribute status.
86 87 88 |
# File 'lib/diecut/report.rb', line 86 def status @status end |
#summary ⇒ Object
Returns the value of attribute summary.
86 87 88 |
# File 'lib/diecut/report.rb', line 86 def summary @summary end |
#summary_count ⇒ Object
Returns the value of attribute summary_count.
86 87 88 |
# File 'lib/diecut/report.rb', line 86 def summary_count @summary_count end |
Instance Method Details
#add(*args) ⇒ Object
88 89 90 |
# File 'lib/diecut/report.rb', line 88 def add(*args) @rejects << args end |
#column_widths ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/diecut/report.rb', line 107 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/diecut/report.rb', line 119 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
103 104 105 |
# File 'lib/diecut/report.rb', line 103 def empty? @rejects.empty? end |
#fail(summary) ⇒ Object
92 93 94 95 96 |
# File 'lib/diecut/report.rb', line 92 def fail(summary) @passed = false @status = "FAIL" @summary = summary end |
#length ⇒ Object Also known as: count
98 99 100 |
# File 'lib/diecut/report.rb', line 98 def length @rejects.length end |
#sized(array, widths) ⇒ Object
115 116 117 |
# File 'lib/diecut/report.rb', line 115 def sized(array, widths) array.take(widths.length).zip(widths).map{|item, width| { it: item.to_s.ljust(width)}} end |