Class: Diff::Hunk
Overview
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.
Instance Attribute Summary collapse
-
#aIdx ⇒ Object
Returns the value of attribute aIdx.
-
#bIdx ⇒ Object
Returns the value of attribute bIdx.
-
#deleteValues ⇒ Object
readonly
Returns the value of attribute deleteValues.
-
#insertValues ⇒ Object
readonly
Returns the value of attribute insertValues.
Instance Method Summary collapse
-
#delete? ⇒ Boolean
Has the Hunk any values to be deleted?.
-
#initialize(aIdx, bIdx) ⇒ Hunk
constructor
Create a new Hunk.
-
#insert? ⇒ Boolean
Has the Hunk any values to insert?.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(aIdx, bIdx) ⇒ Hunk
Create a new Hunk. aIdx is the index in the A list. bIdx is the index in the B list.
33 34 35 36 37 38 39 40 41 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 33 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 |
Instance Attribute Details
#aIdx ⇒ Object
Returns the value of attribute aIdx.
29 30 31 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 29 def aIdx @aIdx end |
#bIdx ⇒ Object
Returns the value of attribute bIdx.
29 30 31 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 29 def bIdx @bIdx end |
#deleteValues ⇒ Object (readonly)
Returns the value of attribute deleteValues.
28 29 30 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 28 def deleteValues @deleteValues end |
#insertValues ⇒ Object (readonly)
Returns the value of attribute insertValues.
28 29 30 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 28 def insertValues @insertValues end |
Instance Method Details
#delete? ⇒ Boolean
Has the Hunk any values to be deleted?
49 50 51 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 49 def delete? !@deleteValues.empty? end |
#insert? ⇒ Boolean
Has the Hunk any values to insert?
44 45 46 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 44 def insert? !@insertValues.empty? end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 72 def inspect puts to_s end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 53 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 |