Class DiffTools::Diff
In: lib/diff_tools.rb
Parent: Object

Methods

<<   []   create   exclude   grep   negative   new   to_s  

Public Class methods

[Source]

# File lib/diff_tools.rb, line 10
    def initialize ( anObject=nil )
      @chunks = {}
      @path_list = PathList.new
      case anObject
      when String
        anObject.split(/^Index: /m).each do |chunk|
          self << 'Index: ' + chunk unless chunk.empty?
        end
      when Diff
        merge! anObject
      when Array
        anObject.flatten.each { |chunk| self << chunk }
      when NilClass
      else
        raise TypeError, "Unexpected type #{anObject.class}"
      end
    end

Public Instance methods

[Source]

# File lib/diff_tools.rb, line 28
    def << ( chunk )
      chunk = Chunk.new(chunk) unless chunk.is_a? Chunk
      if @path_list.include? chunk.path
        raise ArgumentError, "Already have the path `#{chunk.path}'"
      end
      @chunks[chunk.path] = chunk
      @path_list << chunk.path
    end

[Source]

# File lib/diff_tools.rb, line 37
    def [] ( *args )
      grep(*args)
    end

[Source]

# File lib/diff_tools.rb, line 58
    def exclude ( *args )
      create @path_list.exclude_with_regex_list(RegexList.new(args))
    end

[Source]

# File lib/diff_tools.rb, line 50
    def grep ( *args )
      create @path_list.grep_with_regex_list(RegexList.new(args))
    end

[Source]

# File lib/diff_tools.rb, line 54
    def negative ( *args )
      create @path_list.grep_with_negative_regex_list(RegexList.new(args))
    end

[Source]

# File lib/diff_tools.rb, line 62
    def to_s
      @chunks.values.join
    end

Protected Instance methods

[Source]

# File lib/diff_tools.rb, line 41
    def create ( path_list )
      result = Diff.new
      path_list.each do |path|
        result << @chunks[path]
      end
      result
    end

[Validate]