class Mago::Cli::Formatter
Formats report to be printed
Public Class Methods
new(opts = {})
click to toggle source
@param opts [Hash]
@option opts :color [Boolean] whether colorize output or no
# File lib/mago/cli/formatter.rb, line 10 def initialize(opts = {}) @color = opts[:color] end
Public Instance Methods
format(report)
click to toggle source
Format report.
@param report [Mago::Report]
@return [String] formated report
# 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)
click to toggle source
Format error.
@param error [String] error message
@return [void]
# File lib/mago/cli/formatter.rb, line 64 def format_error(error) out = "ERROR: #{error}" @color ? red(out) : out end
format_file(file)
click to toggle source
Format file with magic numbers.
@param file [Mago::File]
@return [void]
# 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