Class: Canon::Comparison::Dimensions::StructuralWhitespaceDimension
- Inherits:
-
BaseDimension
- Object
- BaseDimension
- Canon::Comparison::Dimensions::StructuralWhitespaceDimension
- Defined in:
- lib/canon/comparison/dimensions/structural_whitespace_dimension.rb
Overview
Structural whitespace dimension
Handles comparison of structural whitespace (whitespace between elements). Supports :strict, :normalize, and :ignore behaviors.
Behaviors:
-
:strict - Exact whitespace comparison
-
:normalize - Collapse whitespace and compare
-
:ignore - Skip structural whitespace comparison
Constant Summary
Constants inherited from BaseDimension
BaseDimension::IGNORE, BaseDimension::NORMALIZE, BaseDimension::STRICT
Instance Method Summary collapse
-
#compare_normalize(ws1, ws2) ⇒ Boolean
Normalized structural whitespace comparison.
-
#compare_strict(ws1, ws2) ⇒ Boolean
Strict structural whitespace comparison.
-
#extract_data(node) ⇒ Array<String>
Extract structural whitespace from a node.
Methods inherited from BaseDimension
#compare, #dimension_name, #equivalent?, #supports_normalization?
Instance Method Details
#compare_normalize(ws1, ws2) ⇒ Boolean
Normalized structural whitespace comparison
Collapses whitespace in each entry and compares.
55 56 57 |
# File 'lib/canon/comparison/dimensions/structural_whitespace_dimension.rb', line 55 def compare_normalize(ws1, ws2) # rubocop:disable Naming/PredicateMethod normalize_whitespace(ws1) == normalize_whitespace(ws2) end |
#compare_strict(ws1, ws2) ⇒ Boolean
Strict structural whitespace comparison
44 45 46 |
# File 'lib/canon/comparison/dimensions/structural_whitespace_dimension.rb', line 44 def compare_strict(ws1, ws2) # rubocop:disable Naming/PredicateMethod ws1 == ws2 end |
#extract_data(node) ⇒ Array<String>
Extract structural whitespace from a node
Returns whitespace text nodes that are between elements (structural).
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/canon/comparison/dimensions/structural_whitespace_dimension.rb', line 25 def extract_data(node) return [] 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 [] end end |