Skip to content

Commit 9acc263

Browse files
committed
Added Patch#removed_lines method
1 parent 02ce6f3 commit 9acc263

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/git_diff_parser/patch.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module GitDiffParser
33
class Patch
44
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
55
MODIFIED_LINE = /^\+(?!\+|\+)/
6+
REMOVED_LINE = /^[-]/
67
NOT_REMOVED_LINE = /^[^-]/
78

89
attr_accessor :file, :body, :secure_hash
@@ -76,6 +77,27 @@ def changed_lines
7677
end
7778
end
7879

80+
def removed_lines
81+
line_number = 0
82+
83+
lines.each_with_index.inject([]) do |lines, (content, patch_position)|
84+
case content
85+
when RANGE_INFORMATION_LINE
86+
line_number = Regexp.last_match[:line_number].to_i
87+
when REMOVED_LINE
88+
line = Line.new(
89+
content: content,
90+
number: line_number,
91+
patch_position: patch_position
92+
)
93+
lines << line
94+
line_number += 1
95+
end
96+
97+
lines
98+
end
99+
end
100+
79101
# @return [Array<Integer>] changed line numbers
80102
def changed_line_numbers
81103
changed_lines.map(&:number)

0 commit comments

Comments
 (0)