Class: Pronto::AndroidLint::OutputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/android_lint/output_parser.rb

Constant Summary collapse

TYPE_WARNINGS =
{
  "Warning" => :warning,
  "Info"  => :info
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ OutputParser

Returns a new instance of OutputParser.



14
15
16
# File 'lib/pronto/android_lint/output_parser.rb', line 14

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/pronto/android_lint/output_parser.rb', line 7

def path
  @path
end

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pronto/android_lint/output_parser.rb', line 18

def parse
  lint_result = File.open(@path) { |f| Nokogiri::XML(f) }
  lint_result.xpath("//issue").flat_map do |issue|
    issue.xpath(".//location").map do |location|
      {
        path: location.attribute("file").try(:value),
        line: location.attribute("line").try(:value).to_i,
        level: TYPE_WARNINGS[issue.attribute("severity").value],
        message: create_message(issue)
      }
    end
  end
rescue => e
  raise "Error while parsing file: #{@path}\n#{e.message}"
end