Class: Canon::Comparison::Dimensions::Dimension

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

Overview

Immutable value object representing a single comparison dimension.

A dimension is an aspect of a document that can be compared with different behaviors (e.g., :strict, :normalize, :ignore). Each dimension knows its own classification rules — whether a difference is normative (affects equivalence) for a given behavior, and whether formatting detection should apply.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, valid_behaviors:, normative_rule: :behavior_not_ignore, formatting_detection: false) ⇒ Dimension

Returns a new instance of Dimension.

Parameters:

  • name (Symbol)

    Dimension identifier (e.g., :text_content)

  • valid_behaviors (Array<Symbol>)

    Allowed behaviors

  • normative_rule (Symbol) (defaults to: :behavior_not_ignore)

    :behavior_not_ignore or :strict_only

  • formatting_detection (Boolean) (defaults to: false)

    Whether FormattingDetector applies



20
21
22
23
24
25
26
27
# File 'lib/canon/comparison/dimensions/dimension.rb', line 20

def initialize(name:, valid_behaviors:, normative_rule: :behavior_not_ignore,
               formatting_detection: false)
  @name = name
  @valid_behaviors = valid_behaviors.freeze
  @normative_rule = normative_rule
  @formatting_detection = formatting_detection
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/canon/comparison/dimensions/dimension.rb', line 14

def name
  @name
end

#valid_behaviorsObject (readonly)

Returns the value of attribute valid_behaviors.



14
15
16
# File 'lib/canon/comparison/dimensions/dimension.rb', line 14

def valid_behaviors
  @valid_behaviors
end

Instance Method Details

#normative?(behavior) ⇒ Boolean

Whether a difference in this dimension with the given behavior is normative (affects equivalence).

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/canon/comparison/dimensions/dimension.rb', line 31

def normative?(behavior)
  case @normative_rule
  when :strict_only then behavior == :strict
  else behavior != :ignore
  end
end

#supports_formatting_detection?Boolean

Whether formatting detection should apply to differences in this dimension.

Returns:

  • (Boolean)


45
46
47
# File 'lib/canon/comparison/dimensions/dimension.rb', line 45

def supports_formatting_detection?
  @formatting_detection
end

#valid_behavior?(behavior) ⇒ Boolean

Whether the given behavior is valid for this dimension.

Returns:

  • (Boolean)


39
40
41
# File 'lib/canon/comparison/dimensions/dimension.rb', line 39

def valid_behavior?(behavior)
  @valid_behaviors.include?(behavior)
end