Class: Diff::LCS::Change

### Home Classes Methods

### In Files

- lib/diff/lcs/change.rb

### Parent

Object

### Methods

- ::from_a
- ::new
- ::valid_action?
- #<=>
- #==
- #adding?
- #changed?
- #deleting?
- #finished_a?
- #finished_b?
- #inspect
- #to_a
- #unchanged?

### Included Modules

- Comparable

### Files

- Manifest.txt
- README.rdoc
- COPYING.txt
- artistic.txt

### Class/Module Index

Quicksearch

- Diff
- Diff::LCS
- Diff::LCS::BalancedCallbacks
- Diff::LCS::Block
- Diff::LCS::Change
- Diff::LCS::ContextChange
- Diff::LCS::ContextDiffCallbacks
- Diff::LCS::DefaultCallbacks
- Diff::LCS::DiffCallbacks
- Diff::LCS::HTMLDiff
- Diff::LCS::HTMLDiff::Callbacks
- Diff::LCS::Hunk
- Diff::LCS::Ldiff
- Diff::LCS::SDiffCallbacks
- Diff::LCS::SequenceCallbacks
- Array
- String

No matching classes.

# Diff::LCS::Change

Represents a simplistic (non-contextual) change. Represents the removal or addition of an element from either the old or the new sequenced enumerable.

### Constants

VALID_ACTIONS

  The only actions valid for changes are '+' (add), '-' (delete), '=' (no change), '!' (changed), '<' (tail changes from first sequence), or '>' (tail changes from second sequence). The last two ('<>') are only found with Diff::LCS::diff and Diff::LCS::sdiff.

### Attributes

action[R]

Returns the action this Change represents.

element[R]

Returns the sequence element of the Change.

position[R]

Returns the position of the Change.

### Public Class Methods

from_a(arr) click to toggle source

    # File lib/diff/lcs/change.rb, line 41
    def self.from_a(arr)
      arr = arr.flatten
      case arr.size
      when 5
        Diff::LCS::ContextChange.new(*(arr[0...5]))
      when 3
        Diff::LCS::Change.new(*(arr[0...3]))
      else
        raise "Invalid change array format provided."
      end
    end

new(*args) click to toggle source

    # File lib/diff/lcs/change.rb, line 24
    def initialize(*args)
      @action, @position, @element = *args

      unless Diff::LCS::Change.valid_action?(@action)
        raise "Invalid Change Action '#{@action}'"
      end
      raise "Invalid Position Type" unless @position.kind_of? Fixnum
    end

valid_action?(action) click to toggle source

    # File lib/diff/lcs/change.rb, line 12
    def self.valid_action?(action)
      VALID_ACTIONS.include? action
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/diff/lcs/change.rb, line 61
    def <=>(other)
      r = self.action <=> other.action
      r = self.position <=> other.position if r.zero?
      r = self.element <=> other.element if r.zero?
      r
    end

==(other) click to toggle source

    # File lib/diff/lcs/change.rb, line 55
    def ==(other)
      (self.action == other.action) and
      (self.position == other.position) and
      (self.element == other.element)
    end

adding?() click to toggle source

    # File lib/diff/lcs/change.rb, line 68
    def adding?
      @action == '+'
    end

changed?() click to toggle source

    # File lib/diff/lcs/change.rb, line 80
    def changed?
      @action == '!'
    end

deleting?() click to toggle source

    # File lib/diff/lcs/change.rb, line 72
    def deleting?
      @action == '-'
    end

finished_a?() click to toggle source

    # File lib/diff/lcs/change.rb, line 84
    def finished_a?
      @action == '>'
    end

finished_b?() click to toggle source

    # File lib/diff/lcs/change.rb, line 88
    def finished_b?
      @action == '<'
    end

inspect() click to toggle source

    # File lib/diff/lcs/change.rb, line 33
    def inspect
      to_a.inspect
    end

to_a() click to toggle source

    # File lib/diff/lcs/change.rb, line 37
    def to_a
      [ @action, @position, @element ]
    end

unchanged?() click to toggle source

    # File lib/diff/lcs/change.rb, line 76
    def unchanged?
      @action == '='
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.