Class Diff::Hunk
In: lib/taskjuggler/AlgorithmDiff.rb
Parent: Object

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.

Methods

delete?   insert?   inspect   new   to_s  

Attributes

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

Public Class methods

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

[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

Public Instance methods

Has the Hunk any values to be deleted?

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 48
    def delete?
      !@deleteValues.empty?
    end

Has the Hunk any values to insert?

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 43
    def insert?
      !@insertValues.empty?
    end

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 71
    def inspect
      puts to_s
    end

[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

[Validate]