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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#initialize(violations, options = {}) ⇒ ViolationFormatter
constructor
A new instance of ViolationFormatter.
- #to_s ⇒ Object
Constructor Details
#initialize(violations, options = {}) ⇒ ViolationFormatter
Returns a new instance of ViolationFormatter.
11 12 13 14 15 16 17 18 19 20 |
# 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 @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/cane/violation_formatter.rb', line 9 def @options end |
#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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cane/violation_formatter.rb', line 22 def to_s return "" if violations.empty? string = 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" if violations.count > .fetch(:max_violations, 0) string = colorize(string) end string end |