Class: Canon::Comparison::Dimensions::DimensionSet

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

Overview

Immutable collection of dimensions for a specific format.

Each format (XML, JSON, YAML) has its own DimensionSet listing the comparison aspects relevant to that format. Provides lookup by name, enumeration, and existence checks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, dimensions) ⇒ DimensionSet

Returns a new instance of DimensionSet.

Parameters:

  • format (Symbol)

    Format identifier (e.g., :xml, :json, :yaml)

  • dimensions (Array<Dimension>)

    Dimensions for this format



16
17
18
19
20
21
22
# File 'lib/canon/comparison/dimensions/dimension_set.rb', line 16

def initialize(format, dimensions)
  @format = format
  @dimensions = dimensions.to_h do |dim|
    [dim.name, dim]
  end.freeze
  freeze
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



12
13
14
# File 'lib/canon/comparison/dimensions/dimension_set.rb', line 12

def format
  @format
end

Instance Method Details

#[](name) ⇒ Dimension?

Lookup a dimension by name.

Parameters:

  • name (Symbol)

Returns:



28
29
30
# File 'lib/canon/comparison/dimensions/dimension_set.rb', line 28

def [](name)
  @dimensions[name]
end

#dimension?(name) ⇒ Boolean

Whether this format has a dimension with the given name.

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


43
44
45
# File 'lib/canon/comparison/dimensions/dimension_set.rb', line 43

def dimension?(name)
  @dimensions.key?(name)
end

#namesArray<Symbol>

All dimension names for this format, in definition order.

Returns:

  • (Array<Symbol>)


35
36
37
# File 'lib/canon/comparison/dimensions/dimension_set.rb', line 35

def names
  @dimensions.keys
end