Class: PlatformosCheck::JsonPrinter
- Inherits:
-
Object
- Object
- PlatformosCheck::JsonPrinter
- Defined in:
- lib/platformos_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.
7 8 9 |
# File 'lib/platformos_check/json_printer.rb', line 7 def initialize(out_stream = STDOUT) @out = out_stream end |
Instance Method Details
#offenses_by_path(offenses) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/platformos_check/json_printer.rb', line 16 def offenses_by_path(offenses) offenses .map(&:to_h) .group_by { |offense| offense[:path] } .map do |(path, path_offenses)| { 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
11 12 13 14 |
# File 'lib/platformos_check/json_printer.rb', line 11 def print(offenses) json = offenses_by_path(offenses) @out.puts JSON.dump(json) end |