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

This class is an implementation of the classic UNIX diff functionality. It‘s based on an original implementation by Lars Christensen, which based his version on the Perl Algorithm::Diff implementation. This is largly a from-scratch implementation that tries to have a less intrusive and more user-friendly interface. But some code fragments are very similar to the origninal and are copyright (C) 2001 Lars Christensen.

Methods

editScript   inspect   new   patch   to_s  

Classes and Modules

Class Diff::Hunk

Public Class methods

Create a new Diff between the a list and b list.

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 96
  def initialize(a, b)
    @hunks = []
    diff(a, b)
  end

Public Instance methods

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 115
  def editScript
    script = []
    @hunks.each do |hunk|
      if hunk.delete?
        script << "#{hunk.aIdx + 1}d#{hunk.deleteValues.length}"
      end
      if hunk.insert?
        script << "#{hunk.bIdx + 1}i#{hunk.insertValues.join(',')}"
      end
    end

    script
  end

[Source]

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

Modify the values list according to the stored diff information.

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 102
  def patch(values)
    res = values.dup
    @hunks.each do |hunk|
      if hunk.delete?
        res.slice!(hunk.bIdx, hunk.deleteValues.length)
      end
      if hunk.insert?
        res.insert(hunk.bIdx, *hunk.insertValues)
      end
    end
    res
  end

Return the diff list as standard UNIX diff output.

[Source]

# File lib/taskjuggler/AlgorithmDiff.rb, line 130
  def to_s
    str = ''
    @hunks.each { |hunk| str << hunk.to_s }
    str
  end

[Validate]