Object
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.
Returns the action this Change represents. Can be ’+’ (#), ’-’ (#), ’=’ (#), # or ’!’ (#). When created by Diff::LCS#diff or Diff::LCS#sdiff, it may also be ’>’ (#) or ’<’ (#).
Creates a ContextChange from an array produced by ContextChange#to_a.
# File lib/diff/lcs/change.rb, line 138 138: def self.from_a(arr) 139: if arr.size == 5 140: Diff::LCS::ContextChange.new(arr[0], arr[1], arr[2], arr[3], arr[4]) 141: else 142: Diff::LCS::ContextChange.new(arr[0], arr[1][0], arr[1][1], arr[2][0], 143: arr[2][1]) 144: end 145: end
# File lib/diff/lcs/change.rb, line 125 125: def initialize(action, old_position, old_element, new_position, new_element) 126: @action = action 127: @old_position = old_position 128: @old_element = old_element 129: @new_position = new_position 130: @new_element = new_element 131: 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 149 149: def self.simplify(event) 150: ea = event.to_a 151: 152: case ea[0] 153: when '-' 154: ea[2][1] = nil 155: when '<' 156: ea[0] = '-' 157: ea[2][1] = nil 158: when '+' 159: ea[1][1] = nil 160: when '>' 161: ea[0] = '+' 162: ea[1][1] = nil 163: end 164: 165: Diff::LCS::ContextChange.from_a(ea) 166: end
# File lib/diff/lcs/change.rb, line 116 116: def <=>(other) 117: r = @action <=> other.action 118: r = @old_position <=> other.old_position if r.zero? 119: r = @new_position <=> other.new_position if r.zero? 120: r = @old_element <=> other.old_element if r.zero? 121: r = @new_element <=> other.new_element if r.zero? 122: r 123: end
# File lib/diff/lcs/change.rb, line 104 104: def ==(other) 105: (@action == other.action) and 106: (@old_position == other.old_position) and 107: (@new_position == other.new_position) and 108: (@old_element == other.old_element) and 109: (@new_element == other.new_element) 110: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.