class 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
Returns the new element being changed.
Returns the new position being changed.
Returns the old element being changed.
Returns the old position being changed.
Public Class Methods
# File lib/diff/lcs/change.rb, line 132 def self.from_a(arr) Diff::LCS::Change.from_a(arr) end
# File lib/diff/lcs/change.rb, line 114 def initialize(*args) @action, @old_position, @old_element, @new_position, @new_element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.is_a?(IntClass) fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.is_a?(IntClass) end
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 138 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
# File lib/diff/lcs/change.rb, line 166 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
# File lib/diff/lcs/change.rb, line 157 def ==(other) (self.class == other.class) and (@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
# File lib/diff/lcs/change.rb, line 122 def to_a [ @action, [@old_position, @old_element], [@new_position, @new_element] ] end
Also aliased as: to_ary