Class: Mago::Cli::SourceFormatter
- Defined in:
- lib/mago/cli/source_formatter.rb
Overview
Formats report showing lines of source code where magic number was detected.
Instance Method Summary collapse
-
#format_file(file, out) ⇒ Object
:nodoc:.
-
#make_red(str, substr) ⇒ String
Find a substing in a string and make it red.
Methods inherited from Formatter
Methods included from Colorize
#colorize, #green, #pink, #red, #yellow
Constructor Details
This class inherits a constructor from Mago::Cli::Formatter
Instance Method Details
#format_file(file, out) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mago/cli/source_formatter.rb', line 6 def format_file(file, out) source_lines = File.readlines(file.path) file.magic_numbers.each do |num| if @color line = yellow(num.line) path = pink(file.path) source_line = make_red(source_lines[num.line-1], num.value.to_s) else line = num.line path = file.path source_line = source_lines[num.line-1] end out << "#{path}:#{line}| #{source_line}" end end |
#make_red(str, substr) ⇒ String
Find a substing in a string and make it red.
30 31 32 33 |
# File 'lib/mago/cli/source_formatter.rb', line 30 def make_red(str, substr) chunks = str.split(substr) chunks.join(red(substr)) end |