Class: Canon::Comparison::Dimensions::StructuralWhitespaceDimension

Inherits:
BaseDimension
  • Object
show all
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

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.

Parameters:

  • ws1 (Array<String>)

    First whitespace array

  • ws2 (Array<String>)

    Second whitespace array

Returns:

  • (Boolean)

    true if normalized structural whitespace is equal



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

Parameters:

  • ws1 (Array<String>)

    First whitespace array

  • ws2 (Array<String>)

    Second whitespace array

Returns:

  • (Boolean)

    true if structural whitespace is exactly equal



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).

Parameters:

  • node (Moxml::Node, Nokogiri::XML::Node)

    Node to extract from

Returns:

  • (Array<String>)

    Array of structural whitespace strings



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