Class: FileLinePresenter

Inherits:
Object show all
Defined in:
lib/file_line_presenter.rb

Constant Summary collapse

TAB =
"  "

Class Method Summary collapse

Class Method Details

.present_contents(file_line, pattern, context = 0) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/file_line_presenter.rb', line 7

def self.present_contents(file_line, pattern, context = 0)
  current_highlighted_line = with_line_number(file_line, with_highlighting(file_line, pattern))
  line_number = file_line.line_number
  line_path = file_line.path
  lower_limit = [line_number - context, 1].max
  upper_limit = [line_number + context, file_length(file_line)].min
  above_line_indices = (lower_limit...line_number)
  below_line_indices = (line_number + 1..upper_limit)

  above_lines = numbered_lines_at(above_line_indices, line_path)
  below_lines = numbered_lines_at(below_line_indices, line_path)
  (above_lines + [current_highlighted_line] + below_lines).join("\n")
end