Class: Diecut::ReportFormatter
- Inherits:
-
Object
- Object
- Diecut::ReportFormatter
- Defined in:
- lib/diecut/report.rb
Overview
Adopted gratefully from Xavier Shay’s Cane
Instance Attribute Summary collapse
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
Instance Method Summary collapse
- #context(renderer) ⇒ Object
- #fail_count ⇒ Object
-
#initialize(reports) ⇒ ReportFormatter
constructor
A new instance of ReportFormatter.
- #passed? ⇒ Boolean
- #rejection_fields ⇒ Object
- #template ⇒ Object
- #to_s(widths = nil) ⇒ Object
Constructor Details
#initialize(reports) ⇒ ReportFormatter
Returns a new instance of ReportFormatter.
7 8 9 |
# File 'lib/diecut/report.rb', line 7 def initialize(reports) @reports = reports end |
Instance Attribute Details
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
10 11 12 |
# File 'lib/diecut/report.rb', line 10 def reports @reports end |
Instance Method Details
#context(renderer) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/diecut/report.rb', line 48 def context(renderer) bad_color = proc{|text,render| Paint[renderer.render(text), :red]} good_color = proc{|text,render| Paint[renderer.render(text), :green]} warn_color = proc{|text,render| Paint[renderer.render(text), :yellow]} context = { reports: reports.map(&:context), passed: passed?, total_items: reports.inject(0){|sum, report| sum + report.length}, total_fails: fail_count, status_color: passed? ? good_color : bad_color } context[:reports].each do |report| report[:status_color] = case report[:status] when /ok/i good_color when /fail/i bad_color else warn_color end end context end |
#fail_count ⇒ Object
44 45 46 |
# File 'lib/diecut/report.rb', line 44 def fail_count reports.inject(0){|sum, report| sum + (report.passed ? 0 : 1)} end |
#passed? ⇒ Boolean
40 41 42 |
# File 'lib/diecut/report.rb', line 40 def passed? fail_count == 0 end |
#rejection_fields ⇒ Object
12 13 14 |
# File 'lib/diecut/report.rb', line 12 def rejection_fields %i(file_and_line label value) end |
#template ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/diecut/report.rb', line 16 def template (<<-EOT).gsub(/^ /, '') {{#reports}}{{#status_color}}{{name}}: {{status}} {{#length}} {{length}}{{/length}} {{/status_color}} {{#summary}}{{summary}} {{/summary}}{{^empty }}{{#headers}}{{it}} {{/headers}} {{/empty }}{{#rejects}} {{#reject }}{{it}} {{/reject}} {{/rejects}}{{#advice}} {{advice}} {{/advice}} {{/reports}} {{#status_color}}Total QA report items: {{total_items}} Total QA failing reports: {{total_fails}} {{/status_color}} EOT end |
#to_s(widths = nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/diecut/report.rb', line 33 def to_s(widths=nil) renderer = Mustache.new # require 'pp'; puts "\n#{__FILE__}:#{__LINE__} => {context(renderer).pretty_inspect}" renderer.render(template, context(renderer)) end |