Class: Canon::Comparison::Dimensions::ElementPositionDimension
- Inherits:
-
BaseDimension
- Object
- BaseDimension
- Canon::Comparison::Dimensions::ElementPositionDimension
- Defined in:
- lib/canon/comparison/dimensions/element_position_dimension.rb
Overview
Element position dimension
Handles comparison of element positions within their parent. Supports :strict and :ignore behaviors.
Behaviors:
-
:strict - Elements must appear in the same position (index)
-
:ignore - Element position doesn’t matter
Constant Summary
Constants inherited from BaseDimension
BaseDimension::IGNORE, BaseDimension::NORMALIZE, BaseDimension::STRICT
Instance Method Summary collapse
-
#compare_strict(pos1, pos2) ⇒ Boolean
Strict element position comparison.
-
#extract_data(node) ⇒ Integer
Extract element position from a node.
Methods inherited from BaseDimension
#compare, #compare_normalize, #dimension_name, #equivalent?, #supports_normalization?
Instance Method Details
#compare_strict(pos1, pos2) ⇒ Boolean
Strict element position comparison
42 43 44 |
# File 'lib/canon/comparison/dimensions/element_position_dimension.rb', line 42 def compare_strict(pos1, pos2) # rubocop:disable Naming/PredicateMethod pos1 == pos2 end |
#extract_data(node) ⇒ Integer
Extract element position from a node
Returns the index of this node among its siblings of the same type.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/canon/comparison/dimensions/element_position_dimension.rb', line 23 def extract_data(node) return 0 unless node # Handle Moxml nodes if node.is_a?(Moxml::Node) extract_from_moxml(node) # Handle Nokogiri nodes elsif node.is_a?(Nokogiri::XML::Node) extract_from_nokogiri(node) else 0 end end |