Module: Canon::Comparison::Dimensions::Registry

Defined in:
lib/canon/comparison/dimensions/registry.rb

Overview

Registry for comparison dimensions

Provides a central access point for all dimension classes and maps dimension symbols to their implementations.

Constant Summary collapse

DIMENSION_CLASSES =

Dimension class mappings

{
  text_content: TextContentDimension,
  comments: CommentsDimension,
  attribute_values: AttributeValuesDimension,
  attribute_presence: AttributePresenceDimension,
  attribute_order: AttributeOrderDimension,
  element_position: ElementPositionDimension,
  structural_whitespace: StructuralWhitespaceDimension,
}.freeze

Class Method Summary collapse

Class Method Details

.available_dimensionsArray<Symbol>

Get all available dimension names

Returns:

  • (Array<Symbol>)

    Available dimension names



51
52
53
# File 'lib/canon/comparison/dimensions/registry.rb', line 51

def self.available_dimensions
  DIMENSION_CLASSES.keys
end

.compare(dimension_name, node1, node2, behavior) ⇒ Boolean

Compare two nodes for a specific dimension

Parameters:

  • dimension_name (Symbol)

    Dimension name

  • node1 (Object)

    First node

  • node2 (Object)

    Second node

  • behavior (Symbol)

    Comparison behavior

Returns:

  • (Boolean)

    true if nodes match for this dimension



70
71
72
73
# File 'lib/canon/comparison/dimensions/registry.rb', line 70

def self.compare(dimension_name, node1, node2, behavior) # rubocop:disable Naming/PredicateMethod
  dimension = get(dimension_name)
  dimension.equivalent?(node1, node2, behavior)
end

.dimension_exists?(dimension_name) ⇒ Boolean

Check if a dimension is available

Parameters:

  • dimension_name (Symbol)

    Dimension name

Returns:

  • (Boolean)

    true if dimension is available



59
60
61
# File 'lib/canon/comparison/dimensions/registry.rb', line 59

def self.dimension_exists?(dimension_name)
  DIMENSION_CLASSES.key?(dimension_name)
end

.get(dimension_name) ⇒ BaseDimension

Get a dimension instance by name

Parameters:

  • dimension_name (Symbol)

    Dimension name

Returns:

Raises:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/canon/comparison/dimensions/registry.rb', line 36

def self.get(dimension_name)
  dimension_class = DIMENSION_CLASSES[dimension_name]

  unless dimension_class
    raise Canon::Error,
          "Unknown dimension: #{dimension_name}. " \
          "Valid dimensions: #{DIMENSION_CLASSES.keys.join(', ')}"
  end

  dimension_class.new
end