Parent

Included Modules

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

action[R]

Returns the action this Change represents. Can be ’+’ (#), ’-’ (#), ’=’ (#), # or ’!’ (#). When created by Diff::LCS#diff or Diff::LCS#sdiff, it may also be ’>’ (#) or ’<’ (#).

old_position[R]
old_element[R]
new_position[R]
new_element[R]

Public Class Methods

from_a(arr) click to toggle source

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
new(action, old_position, old_element, new_position, new_element) click to toggle source
     # 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
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 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

Public Instance Methods

<=>(other) click to toggle source
     # 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
==(other) click to toggle source
     # 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
inspect(*args) click to toggle source
     # File lib/diff/lcs/change.rb, line 112
112:   def inspect(*args)
113:     %(#<#{self.class.name}:#{__id__} @action=#{action} positions=#{old_position},#{new_position} elements=#{old_element.inspect},#{new_element.inspect}>)
114:   end
to_a() click to toggle source
     # File lib/diff/lcs/change.rb, line 133
133:   def to_a
134:     [@action, [@old_position, @old_element], [@new_position, @new_element]]
135:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.