Class: Canon::Comparison::Dimensions::Dimension
- Inherits:
-
Object
- Object
- Canon::Comparison::Dimensions::Dimension
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#valid_behaviors ⇒ Object
readonly
Returns the value of attribute valid_behaviors.
Instance Method Summary collapse
-
#initialize(name:, valid_behaviors:, normative_rule: :behavior_not_ignore, formatting_detection: false) ⇒ Dimension
constructor
A new instance of Dimension.
-
#normative?(behavior) ⇒ Boolean
Whether a difference in this dimension with the given behavior is normative (affects equivalence).
-
#supports_formatting_detection? ⇒ Boolean
Whether formatting detection should apply to differences in this dimension.
-
#valid_behavior?(behavior) ⇒ Boolean
Whether the given behavior is valid for this dimension.
Constructor Details
#initialize(name:, valid_behaviors:, normative_rule: :behavior_not_ignore, formatting_detection: false) ⇒ Dimension
Returns a new instance of Dimension.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/canon/comparison/dimensions/dimension.rb', line 14 def name @name end |
#valid_behaviors ⇒ Object (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).
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.
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.
39 40 41 |
# File 'lib/canon/comparison/dimensions/dimension.rb', line 39 def valid_behavior?(behavior) @valid_behaviors.include?(behavior) end |