Class: ThemeCheck::JsonPrinter
- Inherits:
-
Object
- Object
- ThemeCheck::JsonPrinter
- Defined in:
- lib/theme_check/json_printer.rb
Instance Method Summary collapse
-
#initialize(out_stream = STDOUT) ⇒ JsonPrinter
constructor
A new instance of JsonPrinter.
- #offenses_by_path(offenses) ⇒ Object
- #print(offenses) ⇒ Object
Constructor Details
#initialize(out_stream = STDOUT) ⇒ JsonPrinter
Returns a new instance of JsonPrinter.
6 7 8 |
# File 'lib/theme_check/json_printer.rb', line 6 def initialize(out_stream = STDOUT) @out = out_stream end |
Instance Method Details
#offenses_by_path(offenses) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/theme_check/json_printer.rb', line 15 def offenses_by_path(offenses) offenses .map(&:to_h) .group_by { |offense| offense[:path] } .map do |(path, path_offenses)| { path: path, offenses: path_offenses.map { |offense| offense.filter { |k, _v| k != :path } }, errorCount: path_offenses.count { |offense| offense[:severity] == Check::SEVERITY_VALUES[:error] }, suggestionCount: path_offenses.count { |offense| offense[:severity] == Check::SEVERITY_VALUES[:suggestion] }, styleCount: path_offenses.count { |offense| offense[:severity] == Check::SEVERITY_VALUES[:style] }, } end .sort_by { |o| o[:path] || Pathname.new('') } end |
#print(offenses) ⇒ Object
10 11 12 13 |
# File 'lib/theme_check/json_printer.rb', line 10 def print(offenses) json = offenses_by_path(offenses) @out.puts JSON.dump(json) end |