Class: Ducalis::Patch
- Inherits:
-
Object
- Object
- Ducalis::Patch
- Defined in:
- lib/ducalis/patch.rb
Constant Summary collapse
- RANGE_LINE =
/^@@ .+\+(?<line_number>\d+),/.freeze
- MODIFIED_LINE =
/^\+(?!\+|\+)/.freeze
- NOT_REMOVED_LINE =
/^[^-]/.freeze
- ANY_LINE =
/.*/.freeze
- DIFF_LINES =
{ RANGE_LINE => lambda do |lines, _line_number, line, _position| [lines, line.match(RANGE_LINE)[:line_number].to_i] end, MODIFIED_LINE => lambda do |lines, line_number, line, position| [lines + [Line.new(line_number, line, position)], line_number + 1] end, NOT_REMOVED_LINE => lambda do |lines, line_number, _line, _position| [lines, line_number + 1] end, ANY_LINE => lambda do |lines, line_number, _line, _position| [lines, line_number] end }.freeze
Instance Method Summary collapse
-
#initialize(patch) ⇒ Patch
constructor
A new instance of Patch.
- #line_for(line_number) ⇒ Object
Constructor Details
#initialize(patch) ⇒ Patch
Returns a new instance of Patch.
25 26 27 28 |
# File 'lib/ducalis/patch.rb', line 25 def initialize(patch) diff_only = patch[patch.match(RANGE_LINE).begin(0)..-1] @patch_lines = diff_only.lines.to_enum.with_index end |
Instance Method Details
#line_for(line_number) ⇒ Object
30 31 32 33 34 |
# File 'lib/ducalis/patch.rb', line 30 def line_for(line_number) changed_lines.detect do |line| line.number == line_number end || UnchangedLine.new end |