Class: Pronto::Credo::OutputParser
- Inherits:
-
Object
- Object
- Pronto::Credo::OutputParser
- Defined in:
- lib/pronto/credo/output_parser.rb
Constant Summary collapse
- TYPE_WARNINGS =
{ 'R' => :info, 'W' => :warning, 'C' => :info, 'D' => :info, 'F' => :info, 'A' => :info }
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(file, output) ⇒ OutputParser
constructor
A new instance of OutputParser.
- #parse ⇒ Object
Constructor Details
#initialize(file, output) ⇒ OutputParser
Returns a new instance of OutputParser.
13 14 15 16 |
# File 'lib/pronto/credo/output_parser.rb', line 13 def initialize(file, output) @file = file @output = output end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/pronto/credo/output_parser.rb', line 4 def file @file end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/pronto/credo/output_parser.rb', line 4 def output @output end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pronto/credo/output_parser.rb', line 18 def parse output.lines.map do |line| line_parts = line.split(':') next unless file.start_with?(line_parts[0]) offence_in_line = line_parts[1] column_line = nil if line_parts[2].to_i == 0 offence_level = TYPE_WARNINGS[line_parts[2].strip] = line_parts[3..-1].join(':').strip else offence_level = TYPE_WARNINGS[line_parts[3].strip] column_line = line_parts[2].to_i = line_parts[4..-1].join(':').strip end { line: offence_in_line.to_i, column: column_line, level: offence_level, message: } end.compact end |