class Ackr::Formatter

Format strings to be displayed on terminal.

Public Class Methods

new(search_term) click to toggle source

Public:

search_term - The String or Regexp to look for.

# File lib/ackr/formatter.rb, line 10
def initialize search_term
  @search_term = search_term
end

Public Instance Methods

line(line, num) click to toggle source

Public: format a line with matched term(s).

line - The String line to be displayed. num - The Integer number of the line (in base 1).

Returns a formatted String.

# File lib/ackr/formatter.rb, line 20
def line line, num
  begin
    line.strip!
  rescue Exception => ex
    puts "Error ".background(:red) + ex.message
  end
  "#{'%4i' % num}| #{Colorizer::for_line(line, @search_term)}"
end