Class: Diff::LCS::Change
- Includes:
- Comparable, ChangeTypeTests
- Defined in:
- lib/gems/diff-lcs-1.1.2/lib/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
#initialize(action, position, element) ⇒ Change
Returns a new instance of Change.
70 71 72 73 74 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 70 def initialize(action, position, element) @action = action @position = position @element = element end |
Instance Attribute Details
#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?).
52 53 54 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 52 def action @action end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
54 55 56 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 54 def element @element end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
53 54 55 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 53 def position @position end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 63 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 |
#==(other) ⇒ Object
57 58 59 60 61 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 57 def ==(other) (self.action == other.action) and (self.position == other.position) and (self.element == other.element) end |
#to_a ⇒ Object
Creates a Change from an array produced by Change#to_a.
77 78 79 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb', line 77 def to_a [@action, @position, @element] end |