Class: Diff::LCS::ContextChange

### Home Classes Methods

### In Files

- lib/diff/lcs/change.rb

### Parent

Diff::LCS::Change

### Methods

- ::from_a
- ::new
- ::simplify
- #<=>
- #==
- #inspect
- #to_a

### 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::ContextChange

Represents a contextual change. Contains the position and values of the elements in the old and the new sequenced enumerables as well as the action taken.

### Attributes

new_element[R]

Returns the new element being changed.

new_position[R]

Returns the new position being changed.

old_element[R]

Returns the old element being changed.

old_position[R]

Returns the old position being changed.

### Public Class Methods

from_a(arr) click to toggle source

    # File lib/diff/lcs/change.rb, line 135
    def self.from_a(arr)
      Diff::LCS::Change.from_a(arr)
    end

new(*args) click to toggle source

    # File lib/diff/lcs/change.rb, line 110
    def initialize(*args)
      @action, @old_position, @old_element, @new_position, @new_element = *args

      unless Diff::LCS::Change.valid_action?(@action)
        raise "Invalid Change Action '#{@action}'"
      end
      unless @old_position.nil? or @old_position.kind_of? Fixnum
        raise "Invalid (Old) Position Type"
      end
      unless @new_position.nil? or @new_position.kind_of? Fixnum
        raise "Invalid (New) Position Type"
      end
    end

simplify(event) click to toggle source

Simplifies a context change for use in some diff callbacks. '<' actions are converted to '-' and '>' actions are converted to '+'.

    # File lib/diff/lcs/change.rb, line 141
    def self.simplify(event)
      ea = event.to_a

      case ea[0]
      when '-'
        ea[2][1] = nil
      when '<'
        ea[0] = '-'
        ea[2][1] = nil
      when '+'
        ea[1][1] = nil
      when '>'
        ea[0] = '+'
        ea[1][1] = nil
      end

      Diff::LCS::ContextChange.from_a(ea)
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/diff/lcs/change.rb, line 168
    def <=>(other)
      r = @action <=> other.action
      r = @old_position <=> other.old_position if r.zero?
      r = @new_position <=> other.new_position if r.zero?
      r = @old_element <=> other.old_element if r.zero?
      r = @new_element <=> other.new_element if r.zero?
      r
    end

==(other) click to toggle source

    # File lib/diff/lcs/change.rb, line 160
    def ==(other)
      (@action == other.action) and
      (@old_position == other.old_position) and
      (@new_position == other.new_position) and
      (@old_element == other.old_element) and
      (@new_element == other.new_element)
    end

inspect(*args) click to toggle source

    # File lib/diff/lcs/change.rb, line 131
    def inspect(*args)
      to_a.inspect
    end

to_a() click to toggle source

    # File lib/diff/lcs/change.rb, line 124
    def to_a
      [ @action,
        [ @old_position, @old_element ],
        [ @new_position, @new_element ]
      ]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.