Class: PlatformosCheck::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/platformos_check/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(out_stream = STDOUT) ⇒ Printer

Returns a new instance of Printer.



5
6
7
# File 'lib/platformos_check/printer.rb', line 5

def initialize(out_stream = STDOUT)
  @out = out_stream
end

Instance Method Details



9
10
11
12
13
14
15
16
17
18
# File 'lib/platformos_check/printer.rb', line 9

def print(platformos_app, offenses, auto_correct)
  offenses.each do |offense|
    print_offense(offense, auto_correct)
    @out.puts
  end

  correctable = offenses.select(&:correctable?)
  @out.puts "#{platformos_app.all.size} files inspected, #{red(offenses.size.to_s + ' offenses')} detected, \
#{yellow(correctable.size.to_s + ' offenses')} #{auto_correct ? 'corrected' : 'auto-correctable'}"
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/platformos_check/printer.rb', line 20

def print_offense(offense, auto_correct)
  location = if offense.location
               blue(offense.location) + ": "
             else
               ""
             end

  corrected = if auto_correct && offense.correctable?
                green("[Corrected] ")
              else
                ""
              end

  @out.puts location +
            colorized_severity(offense.severity) + ": " +
            yellow(offense.check_name) + ": " +
            corrected +
            offense.message + "."
  return unless offense.source_excerpt

  @out.puts "\t#{offense.source_excerpt}"
  return unless offense.markup_start_in_excerpt

  @out.puts "\t" + (" " * offense.markup_start_in_excerpt) + ("^" * offense.markup.size)
end