Class: Telebugs::CodeHunk

Inherits:
Object
  • Object
show all
Defined in:
lib/telebugs/code_hunk.rb

Overview

Represents a small hunk of code consisting of a base line and a couple lines around it

Constant Summary collapse

MAX_LINE_LEN =
200
AROUND_LINES =

How many lines should be read around the base line.

2

Class Method Summary collapse

Class Method Details

.get(file, line) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/telebugs/code_hunk.rb', line 12

def self.get(file, line)
  start_line = [line - AROUND_LINES, 1].max

  lines = get_lines(file, start_line, line + AROUND_LINES)
  return {start_line: 0, lines: []} if lines.empty?

  {
    start_line: start_line,
    lines: lines
  }
end