Class: Diecut::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/diecut/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adviceObject

Returns the value of attribute advice.



96
97
98
# File 'lib/diecut/report.rb', line 96

def advice
  @advice
end

#column_headersObject (readonly)

Returns the value of attribute column_headers.



95
96
97
# File 'lib/diecut/report.rb', line 95

def column_headers
  @column_headers
end

#nameObject (readonly)

Returns the value of attribute name.



95
96
97
# File 'lib/diecut/report.rb', line 95

def name
  @name
end

#passedObject

Returns the value of attribute passed.



96
97
98
# File 'lib/diecut/report.rb', line 96

def passed
  @passed
end

#rejectsObject (readonly)

Returns the value of attribute rejects.



95
96
97
# File 'lib/diecut/report.rb', line 95

def rejects
  @rejects
end

#statusObject

Returns the value of attribute status.



96
97
98
# File 'lib/diecut/report.rb', line 96

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



96
97
98
# File 'lib/diecut/report.rb', line 96

def summary
  @summary
end

#summary_countObject

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_widthsObject



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

#contextObject



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

Returns:

  • (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

#lengthObject 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