Class: Danger::MatchesInDiff::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/diff_todo_finder.rb

Overview

Parsed patch

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Patch

Returns a new instance of Patch.



72
73
74
# File 'lib/todoist/diff_todo_finder.rb', line 72

def initialize(body)
  @body = body
end

Instance Method Details

#changed_linesObject

rubocop:disable Metrics/MethodLength



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/todoist/diff_todo_finder.rb', line 77

def changed_lines
  line_number = 0

  lines_with_index
    .each_with_object([]) do |(content, patch_position), lines|
      case content
      when RANGE_INFORMATION_LINE
        line_number = Regexp.last_match[:line_number].to_i
      when MODIFIED_LINE
        lines << Line.new(content, line_number, patch_position)
        line_number += 1
      when NOT_REMOVED_LINE
        line_number += 1
      end
    end
end

#linesObject

rubocop:enable Metrics/MethodLength



95
96
97
# File 'lib/todoist/diff_todo_finder.rb', line 95

def lines
  @body.lines
end

#lines_with_indexObject



99
100
101
# File 'lib/todoist/diff_todo_finder.rb', line 99

def lines_with_index
  lines.each_with_index
end