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

aIdx[RW]
bIdx[RW]
deleteValues[R]
insertValues[R]

Public Class Methods

new(aIdx, bIdx) click to toggle source

Create a new Hunk. aIdx is the index in the A list. bIdx is the index in the B list.

# 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

Public Instance Methods

delete?() click to toggle source

Has the Hunk any values to be deleted?

# File lib/taskjuggler/AlgorithmDiff.rb, line 48
def delete?
  !@deleteValues.empty?
end
insert?() click to toggle source

Has the Hunk any values to insert?

# File lib/taskjuggler/AlgorithmDiff.rb, line 43
def insert?
  !@insertValues.empty?
end
inspect() click to toggle source
# File lib/taskjuggler/AlgorithmDiff.rb, line 71
def inspect
  puts to_s
end
to_s() click to toggle 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