class Rgr::ColouredReporter

Attributes

output[R]

Public Class Methods

new(output = $stdout) click to toggle source
# File lib/rgr/coloured_reporter.rb, line 7
def initialize(output = $stdout)
  @output = output
end

Public Instance Methods

highlight_source(source) click to toggle source
# File lib/rgr/coloured_reporter.rb, line 28
def highlight_source(source)
  CodeRay.scan(source, :ruby).terminal
end
line_number_places(matches) click to toggle source
# File lib/rgr/coloured_reporter.rb, line 23
def line_number_places(matches)
  highest_line_number = matches.map { |match| match.expression.line }.max
  highest_line_number.to_s.length
end
report_file_matches(file, matches) click to toggle source
# File lib/rgr/coloured_reporter.rb, line 11
def report_file_matches(file, matches)
  output.puts "\e[32;1m#{file}\e[0m"

  line_number_places = line_number_places(matches)

  matches.each do |match|
    expr = match.expression
    highlighted_source = highlight_source(expr.source_line)
    output.printf "\e[33;1m%#{line_number_places}d\e[0m: %s\n", expr.line, highlighted_source
  end
end