Class: Ackr::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ackr/formatter.rb

Overview

Format strings to be displayed on terminal.

Instance Method Summary collapse

Constructor Details

#initialize(search_term) ⇒ Formatter

Public:

search_term - The String or Regexp to look for.



11
12
13
# File 'lib/ackr/formatter.rb', line 11

def initialize search_term
  @search_term = search_term
end

Instance Method Details

#line(line, num) ⇒ Object

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.



21
22
23
24
25
26
27
28
# File 'lib/ackr/formatter.rb', line 21

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