Class: Cane::ViolationFormatter
- Inherits:
-
Object
- Object
- Cane::ViolationFormatter
- Defined in:
- lib/cane/violation_formatter.rb
Overview
Computes a string to be displayed as output from an array of violations computed by the checks.
Instance Attribute Summary collapse
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#initialize(violations) ⇒ ViolationFormatter
constructor
A new instance of ViolationFormatter.
- #to_s ⇒ Object
Constructor Details
#initialize(violations) ⇒ ViolationFormatter
Returns a new instance of ViolationFormatter.
11 12 13 14 15 16 17 18 |
# File 'lib/cane/violation_formatter.rb', line 11 def initialize(violations) @violations = violations.map do |v| v.merge(file_and_line: v[:line] ? "%s:%i" % v.values_at(:file, :line) : v[:file] ) end end |
Instance Attribute Details
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
9 10 11 |
# File 'lib/cane/violation_formatter.rb', line 9 def violations @violations end |
Instance Method Details
#to_s ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cane/violation_formatter.rb', line 20 def to_s return "" if violations.empty? violations.group_by {|x| x[:description] }.map do |d, vs| format_group_header(d, vs) + format_violations(vs) end.join("\n") + "\n\n" + totals + "\n\n" end |