class 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

IntClass
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 44
def self.from_a(arr)
  arr = arr.flatten(1)
  case arr.size
  when 5
    Diff::LCS::ContextChange.new(*(arr[0...5]))
  when 3
    Diff::LCS::Change.new(*(arr[0...3]))
  else
    fail "Invalid change array format provided."
  end
end
new(*args) click to toggle source
# File lib/diff/lcs/change.rb, line 27
def initialize(*args)
  @action, @position, @element = *args

  fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action)
  fail "Invalid Position Type" unless @position.is_a? IntClass
end
valid_action?(action) click to toggle source
# File lib/diff/lcs/change.rb, line 15
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 65
def <=>(other)
  r = action <=> other.action
  r = position <=> other.position if r.zero?
  r = element <=> other.element if r.zero?
  r
end
==(other) click to toggle source
# File lib/diff/lcs/change.rb, line 58
def ==(other)
  (self.class == other.class) and
    (action == other.action) and
    (position == other.position) and
    (element == other.element)
end
adding?() click to toggle source
# File lib/diff/lcs/change.rb, line 72
def adding?
  @action == "+"
end
changed?() click to toggle source
# File lib/diff/lcs/change.rb, line 84
def changed?
  @action == "!"
end
deleting?() click to toggle source
# File lib/diff/lcs/change.rb, line 76
def deleting?
  @action == "-"
end
finished_a?() click to toggle source
# File lib/diff/lcs/change.rb, line 88
def finished_a?
  @action == ">"
end
finished_b?() click to toggle source
# File lib/diff/lcs/change.rb, line 92
def finished_b?
  @action == "<"
end
inspect(*_args) click to toggle source
# File lib/diff/lcs/change.rb, line 34
def inspect(*_args)
  "#<#{self.class}: #{to_a.inspect}>"
end
to_a() click to toggle source
# File lib/diff/lcs/change.rb, line 38
def to_a
  [@action, @position, @element]
end
Also aliased as: to_ary
to_ary()
Alias for: to_a
unchanged?() click to toggle source
# File lib/diff/lcs/change.rb, line 80
def unchanged?
  @action == "="
end