class Diff::Hunk
A Hunk
stores all information about a contiguous change of the destination list. It stores the inserted and deleted values as well as their positions in the A and B list.
Attributes
Public Class Methods
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 32 def initialize(aIdx, bIdx) @aIdx = aIdx # A list of values to be deleted from the A list starting at aIdx. @deleteValues = [] @bIdx = bIdx # A list of values to be inserted into the B list at bIdx. @insertValues = [] end
Create a new Hunk
. aIdx is the index in the A list. bIdx is the index in the B list.
Public Instance Methods
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 48 def delete? !@deleteValues.empty? end
Has the Hunk
any values to be deleted?
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 43 def insert? !@insertValues.empty? end
Has the Hunk
any values to insert?
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 52 def to_s str = '' showSeparator = false if insert? && delete? str << "#{aRange}c#{bRange}\n" showSeparator = true elsif insert? str << "#{aIdx}a#{bRange}\n" else str << "#{aRange}d#{bIdx}\n" end @deleteValues.each { |value| str << "< #{value}\n" } str << "---\n" if showSeparator @insertValues.each { |value| str << "> #{value}\n" } str end
Private Instance Methods
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 77 def aRange range(@aIdx + 1, @aIdx + @deleteValues.length) end
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 81 def bRange range(@bIdx + 1, @bIdx + @insertValues.length) end
Source
# File lib/taskjuggler/AlgorithmDiff.rb, line 85 def range(startIdx, endIdx) if (startIdx == endIdx) "#{startIdx}" else "#{startIdx},#{endIdx}" end end