Class: RuboCop::Git::Patch
- Inherits:
-
Object
- Object
- RuboCop::Git::Patch
- Defined in:
- lib/rubocop/git/patch.rb
Overview
Constant Summary collapse
- RANGE_INFORMATION_LINE =
/^@@ .+\+(?<line_number>\d+),/.freeze
- MODIFIED_LINE =
/^\+(?!\+|\+)/.freeze
- NOT_REMOVED_LINE =
/^[^-]/.freeze
Instance Method Summary collapse
-
#changed_lines ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(body) ⇒ Patch
constructor
A new instance of Patch.
Constructor Details
#initialize(body) ⇒ Patch
Returns a new instance of Patch.
7 8 9 |
# File 'lib/rubocop/git/patch.rb', line 7 def initialize(body) @body = body || '' end |
Instance Method Details
#changed_lines ⇒ Object
rubocop:disable Metrics/MethodLength
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubocop/git/patch.rb', line 11 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 = RuboCop::Git::Line.new(content, line_number, patch_position) hash[line_number] = line line_number += 1 when NOT_REMOVED_LINE line_number += 1 end end end |