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.



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

#adviceObject

Returns the value of attribute advice.



86
87
88
# File 'lib/diecut/report.rb', line 86

def advice
  @advice
end

#column_headersObject (readonly)

Returns the value of attribute column_headers.



85
86
87
# File 'lib/diecut/report.rb', line 85

def column_headers
  @column_headers
end

#nameObject (readonly)

Returns the value of attribute name.



85
86
87
# File 'lib/diecut/report.rb', line 85

def name
  @name
end

#passedObject

Returns the value of attribute passed.



86
87
88
# File 'lib/diecut/report.rb', line 86

def passed
  @passed
end

#rejectsObject (readonly)

Returns the value of attribute rejects.



85
86
87
# File 'lib/diecut/report.rb', line 85

def rejects
  @rejects
end

#statusObject

Returns the value of attribute status.



86
87
88
# File 'lib/diecut/report.rb', line 86

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



86
87
88
# File 'lib/diecut/report.rb', line 86

def summary
  @summary
end

#summary_countObject

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_widthsObject



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

#contextObject



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

Returns:

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

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