Class: Policial::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/policial/patch.rb

Overview

Public: a chunk of changed code in a commit file.

Constant Summary collapse

RANGE_INFORMATION_LINE =
/^@@ .+\+(?<line_number>\d+),/
MODIFIED_LINE =
/^\+(?!\+|\+)/
NOT_REMOVED_LINE =
/^[^-]/

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Patch

Returns a new instance of Patch.



10
11
12
# File 'lib/policial/patch.rb', line 10

def initialize(body)
  @body = body || ''
end

Instance Method Details

#changed_linesObject



14
15
16
17
18
19
20
21
# File 'lib/policial/patch.rb', line 14

def changed_lines
  line_number = 0

  @body.lines.each_with_index.with_object([]) do |(line, patch_pos), lines|
    line_number =
      parse_line(line, line_number, patch_pos, lines) || line_number
  end
end