class Grepity::Line

Attributes

contents[R]
number[R]

Public Class Methods

new(contents, number) click to toggle source
# File lib/grepity/line.rb, line 7
def initialize(contents, number)
  @contents, @number = contents, number + 1
end

Public Instance Methods

result(text, options = {}) click to toggle source
# File lib/grepity/line.rb, line 11
def result(text, options = {})
  return colorized_line_with_text(number, text) if options[:line]
  colorized_text(text)
end

Private Instance Methods

colorized_line_with_text(number, text) click to toggle source
# File lib/grepity/line.rb, line 23
def colorized_line_with_text(number, text)
  "#{number.to_s.green}: #{colorized_text(text)}"
end
colorized_text(text) click to toggle source
# File lib/grepity/line.rb, line 18
def colorized_text(text)
  matched_text = @contents.match(text)[0].yellow
  @contents.gsub(text, matched_text)
end