Class: PlatformosCheck::Printer
- Inherits:
-
Object
- Object
- PlatformosCheck::Printer
- Defined in:
- lib/platformos_check/printer.rb
Instance Method Summary collapse
-
#initialize(out_stream = STDOUT) ⇒ Printer
constructor
A new instance of Printer.
- #print(platformos_app, offenses, auto_correct) ⇒ Object
- #print_offense(offense, auto_correct) ⇒ Object
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
#print(platformos_app, offenses, auto_correct) ⇒ Object
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 |
#print_offense(offense, auto_correct) ⇒ Object
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. + "." 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 |