Class: Canon::Comparison::Dimensions::AttributeOrderDimension

Inherits:
BaseDimension
  • Object
show all
Defined in:
lib/canon/comparison/dimensions/attribute_order_dimension.rb

Overview

Attribute order dimension

Handles comparison of attribute ordering. Supports :strict and :ignore behaviors.

Behaviors:

  • :strict - Attributes must appear in the same order

  • :ignore - Attribute order doesn’t matter

Constant Summary

Constants inherited from BaseDimension

BaseDimension::IGNORE, BaseDimension::NORMALIZE, BaseDimension::STRICT

Instance Method Summary collapse

Methods inherited from BaseDimension

#compare, #compare_normalize, #dimension_name, #equivalent?, #supports_normalization?

Instance Method Details

#compare_strict(order1, order2) ⇒ Boolean

Strict attribute order comparison

Parameters:

  • order1 (Array<Symbol>)

    First attribute order

  • order2 (Array<Symbol>)

    Second attribute order

Returns:

  • (Boolean)

    true if attribute order is exactly the same



40
41
42
# File 'lib/canon/comparison/dimensions/attribute_order_dimension.rb', line 40

def compare_strict(order1, order2) # rubocop:disable Naming/PredicateMethod
  order1 == order2
end

#extract_data(node) ⇒ Array<Symbol>

Extract attribute order from a node

Parameters:

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

    Node to extract from

Returns:

  • (Array<Symbol>)

    Array of attribute names in order



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/canon/comparison/dimensions/attribute_order_dimension.rb', line 21

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