Class: RubyGrep::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-grep/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents, number, file) ⇒ Line

Returns a new instance of Line.



7
8
9
10
11
12
# File 'lib/ruby-grep/line.rb', line 7

def initialize(contents, number, file)
  @contents  = contents
  @number    = number + 1
  @file      = file
  @file_name = @file.file_name
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



5
6
7
# File 'lib/ruby-grep/line.rb', line 5

def contents
  @contents
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/ruby-grep/line.rb', line 5

def file
  @file
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/ruby-grep/line.rb', line 5

def number
  @number
end

Instance Method Details

#aligned_line_numberObject



18
19
20
21
# File 'lib/ruby-grep/line.rb', line 18

def aligned_line_number
  shift = @file.max_line_number_length
  sprintf("%#{shift}d", @number)
end

#colorized_line(expression) ⇒ Object



14
15
16
# File 'lib/ruby-grep/line.rb', line 14

def colorized_line(expression)
  "\s\s\s\s#{colorize_line_number(aligned_line_number)}: #{colorize_text(expression).lstrip}"
end