Class: Mago::Cli::Formatter
- Inherits:
-
Object
- Object
- Mago::Cli::Formatter
- Includes:
- Colorize
- Defined in:
- lib/mago/cli/formatter.rb
Overview
Formats report to be printed
Direct Known Subclasses
Instance Method Summary collapse
-
#format(report) ⇒ String
Format report.
-
#format_error(error) ⇒ void
Format error.
-
#format_file(file) ⇒ void
Format file with magic numbers.
-
#initialize(opts = {}) ⇒ Formatter
constructor
A new instance of Formatter.
Methods included from Colorize
#colorize, #green, #pink, #red, #yellow
Constructor Details
#initialize(opts = {}) ⇒ Formatter
Returns a new instance of Formatter.
10 11 12 |
# File 'lib/mago/cli/formatter.rb', line 10 def initialize(opts = {}) @color = opts[:color] end |
Instance Method Details
#format(report) ⇒ String
Format report.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mago/cli/formatter.rb', line 19 def format(report) out = '' report.files.each do |file| out << format_file(file, out) end report.errors.each do |error| out << format_error(error) end out end |
#format_error(error) ⇒ void
This method returns an undefined value.
Format error.
64 65 66 67 |
# File 'lib/mago/cli/formatter.rb', line 64 def format_error(error) out = "ERROR: #{error}" @color ? red(out) : out end |
#format_file(file) ⇒ void
This method returns an undefined value.
Format file with magic numbers.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mago/cli/formatter.rb', line 39 def format_file(file) out = '' file.magic_numbers.each do |num| if @color val = red(num.value) line = yellow(num.line) path = pink(file.path) else val = num.value line = num.line path = file.path end out << "#{path}:#{line} detected magic number #{val}\n" end out end |