Class: Diff::LCS::Change
- Inherits:
-
Object
- Object
- Diff::LCS::Change
- Includes:
- Comparable, ChangeTypeTests
- Defined in:
- lib/watobo/external/diff/lcs/change.rb
Overview
Represents a simplistic (non-contextual) change. Represents the removal or addition of an element from either the old or the new sequenced enumerable.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the action this Change represents.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(action, position, element) ⇒ Change
constructor
A new instance of Change.
-
#to_a ⇒ Object
Creates a Change from an array produced by Change#to_a.
Methods included from ChangeTypeTests
#adding?, #changed?, #deleting?, #finished_a?, #finished_b?, #unchanged?
Constructor Details
permalink #initialize(action, position, element) ⇒ Change
Returns a new instance of Change.
91 92 93 94 95 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 91 def initialize(action, position, element) @action = action @position = position @element = element end |
Instance Attribute Details
permalink #action ⇒ Object (readonly)
Returns the action this Change represents. Can be ‘+’ (#adding?), ‘-’ (#deleting?), ‘=’ (#unchanged?), # or ‘!’ (#changed?). When created by Diff::LCS#diff or Diff::LCS#sdiff, it may also be ‘>’ (#finished_a?) or ‘<’ (#finished_b?).
73 74 75 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 73 def action @action end |
permalink #element ⇒ Object (readonly)
Returns the value of attribute element.
75 76 77 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 75 def element @element end |
permalink #position ⇒ Object (readonly)
Returns the value of attribute position.
74 75 76 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 74 def position @position end |
Class Method Details
Instance Method Details
permalink #<=>(other) ⇒ Object
[View source]
84 85 86 87 88 89 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 84 def <=>(other) r = self.action <=> other.action r = self.position <=> other.position if r.zero? r = self.element <=> other.element if r.zero? r end |
permalink #==(other) ⇒ Object
[View source]
78 79 80 81 82 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 78 def ==(other) (self.action == other.action) and (self.position == other.position) and (self.element == other.element) end |
permalink #to_a ⇒ Object
Creates a Change from an array produced by Change#to_a.
98 99 100 |
# File 'lib/watobo/external/diff/lcs/change.rb', line 98 def to_a [@action, @position, @element] end |