Class: Undercover::Checkstyle::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/undercover/checkstyle/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ Formatter

Returns a new instance of Formatter.



9
10
11
# File 'lib/undercover/checkstyle/formatter.rb', line 9

def initialize(results)
  @results = results
end

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/undercover/checkstyle/formatter.rb', line 13

def to_s
  file_annotations = warnings_to_annotations.group_by { |annotation| annotation[:path] }

  doc = REXML::Document.new
  doc << REXML::XMLDecl.new('1.0', 'UTF-8')
  checkstyle = REXML::Element.new('checkstyle', doc)
  file_annotations.each do |path, annotations|
    checkstyle << file_element(path, annotations)
  end

  output = StringIO.new
  pretty_formatter = REXML::Formatters::Pretty.new
  pretty_formatter.write(doc, output)
  output.string
end