Class: RuboCop::Git::Patch

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

Overview

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.



8
9
10
# File 'lib/rubocop/git/patch.rb', line 8

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

Instance Method Details

#changed_linesObject

rubocop:disable Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubocop/git/patch.rb', line 12

def changed_lines # rubocop:disable Metrics/MethodLength
  line_number = 0
  lines.
    each_with_object({}).
    with_index do |(content, hash), patch_position|
    case content
    when RANGE_INFORMATION_LINE
      line_number = Regexp.last_match[:line_number].to_i
    when MODIFIED_LINE
      line = Line.new(content, line_number, patch_position)
      hash[line_number] = line
      line_number += 1
    when NOT_REMOVED_LINE
      line_number += 1
    end
  end
end