Class: Canon::Xml::ElementMatcher::MatchResult
- Inherits:
-
Object
- Object
- Canon::Xml::ElementMatcher::MatchResult
- Defined in:
- lib/canon/xml/element_matcher.rb
Overview
Represents the result of matching an element across two DOM trees
A MatchResult indicates whether an element was found in both trees (matched), only in the first tree (deleted), or only in the second tree (inserted).
Attributes
-
status: Symbol indicating match type (:matched, :deleted, :inserted)
-
elem1: Element from first tree (nil if inserted)
-
elem2: Element from second tree (nil if deleted)
-
path: Array of element names showing location in tree
-
pos1: Integer index of elem1 in its parent’s children (nil if inserted)
-
pos2: Integer index of elem2 in its parent’s children (nil if deleted)
Position Change Detection
When status is :matched and pos1 ≠ pos2, the element has moved positions. This is tracked as a semantic difference via the :element_position dimension.
Instance Attribute Summary collapse
-
#elem1 ⇒ Object
readonly
Returns the value of attribute elem1.
-
#elem2 ⇒ Object
readonly
Returns the value of attribute elem2.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pos1 ⇒ Object
readonly
Returns the value of attribute pos1.
-
#pos2 ⇒ Object
readonly
Returns the value of attribute pos2.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#deleted? ⇒ Boolean
True if element only in first tree.
-
#initialize(status:, elem1:, elem2:, path:, pos1: nil, pos2: nil) ⇒ MatchResult
constructor
A new instance of MatchResult.
-
#inserted? ⇒ Boolean
True if element only in second tree.
-
#matched? ⇒ Boolean
True if element found in both trees.
-
#position_changed? ⇒ Boolean
True if element moved to different position.
Constructor Details
#initialize(status:, elem1:, elem2:, path:, pos1: nil, pos2: nil) ⇒ MatchResult
Returns a new instance of MatchResult.
87 88 89 90 91 92 93 94 |
# File 'lib/canon/xml/element_matcher.rb', line 87 def initialize(status:, elem1:, elem2:, path:, pos1: nil, pos2: nil) @status = status @elem1 = elem1 @elem2 = elem2 @path = path @pos1 = pos1 @pos2 = pos2 end |
Instance Attribute Details
#elem1 ⇒ Object (readonly)
Returns the value of attribute elem1.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def elem1 @elem1 end |
#elem2 ⇒ Object (readonly)
Returns the value of attribute elem2.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def elem2 @elem2 end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def path @path end |
#pos1 ⇒ Object (readonly)
Returns the value of attribute pos1.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def pos1 @pos1 end |
#pos2 ⇒ Object (readonly)
Returns the value of attribute pos2.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def pos2 @pos2 end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
79 80 81 |
# File 'lib/canon/xml/element_matcher.rb', line 79 def status @status end |
Instance Method Details
#deleted? ⇒ Boolean
Returns true if element only in first tree.
107 108 109 |
# File 'lib/canon/xml/element_matcher.rb', line 107 def deleted? status == :deleted end |
#inserted? ⇒ Boolean
Returns true if element only in second tree.
102 103 104 |
# File 'lib/canon/xml/element_matcher.rb', line 102 def inserted? status == :inserted end |
#matched? ⇒ Boolean
Returns true if element found in both trees.
97 98 99 |
# File 'lib/canon/xml/element_matcher.rb', line 97 def matched? status == :matched end |
#position_changed? ⇒ Boolean
Returns true if element moved to different position.
112 113 114 |
# File 'lib/canon/xml/element_matcher.rb', line 112 def position_changed? matched? && pos1 && pos2 && pos1 != pos2 end |