Class: Diff::Hunk

Inherits:
Object show all
Defined in:
lib/taskjuggler/AlgorithmDiff.rb

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

Instance Method Summary collapse

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.



32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#aIdxObject

Returns the value of attribute aIdx.



28
29
30
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 28

def aIdx
  @aIdx
end

#bIdxObject

Returns the value of attribute bIdx.



28
29
30
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 28

def bIdx
  @bIdx
end

#deleteValuesObject (readonly)

Returns the value of attribute deleteValues.



27
28
29
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 27

def deleteValues
  @deleteValues
end

#insertValuesObject (readonly)

Returns the value of attribute insertValues.



27
28
29
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 27

def insertValues
  @insertValues
end

Instance Method Details

#delete?Boolean

Has the Hunk any values to be deleted?

Returns:

  • (Boolean)


48
49
50
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 48

def delete?
  !@deleteValues.empty?
end

#insert?Boolean

Has the Hunk any values to insert?

Returns:

  • (Boolean)


43
44
45
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 43

def insert?
  !@insertValues.empty?
end

#inspectObject



71
72
73
# File 'lib/taskjuggler/AlgorithmDiff.rb', line 71

def inspect
  puts to_s
end

#to_sObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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