Class: Canon::Comparison::CompareProfile

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

Overview

CompareProfile encapsulates the policy decisions about how differences in various dimensions should be handled during comparison.

This class provides separation of concerns:

  • CompareProfile: Policy decisions (what to track, what affects equivalence)

  • Comparator: Comparison logic (detect differences)

  • DiffClassifier: Classification logic (normative vs informative vs formatting)

Direct Known Subclasses

HtmlCompareProfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match_options) ⇒ CompareProfile

Returns a new instance of CompareProfile.

Parameters:



16
17
18
# File 'lib/canon/comparison/compare_profile.rb', line 16

def initialize(match_options)
  @match_options = match_options
end

Instance Attribute Details

#match_optionsObject (readonly)

Returns the value of attribute match_options.



13
14
15
# File 'lib/canon/comparison/compare_profile.rb', line 13

def match_options
  @match_options
end

Instance Method Details

#affects_equivalence?(dimension) ⇒ Boolean

Should differences in this dimension affect equivalence?

Parameters:

  • dimension (Symbol)

    The match dimension to check

Returns:

  • (Boolean)

    true if differences affect equivalence



28
29
30
31
# File 'lib/canon/comparison/compare_profile.rb', line 28

def affects_equivalence?(dimension)
  behavior = behavior_for(dimension)
  behavior != :ignore
end

#behavior_for(dimension) ⇒ Symbol

Get the behavior setting for a dimension

Parameters:

  • dimension (Symbol)

    The match dimension

Returns:

  • (Symbol)

    The behavior (:strict, :normalize, :ignore)



65
66
67
68
69
70
71
72
73
# File 'lib/canon/comparison/compare_profile.rb', line 65

def behavior_for(dimension)
  if match_options.is_a?(ResolvedMatchOptions)
    match_options.behavior_for(dimension)
  elsif match_options.is_a?(Hash)
    match_options[dimension] || :strict
  else
    :strict
  end
end

#normative_dimension?(dimension) ⇒ Boolean

Is a difference in this dimension normative (affects equivalence)?

Delegates to the Dimension object’s normative? rule. Falls back to the default rule (normative unless :ignore) for dimensions not in the format’s dimension set (e.g., derived dimensions like :element_structure).

Parameters:

  • dimension (Symbol)

    The match dimension to check

Returns:

  • (Boolean)

    true if normative, false if informative



41
42
43
44
45
46
47
48
# File 'lib/canon/comparison/compare_profile.rb', line 41

def normative_dimension?(dimension)
  dim = dimension_for(dimension)
  if dim
    dim.normative?(behavior_for(dimension))
  else
    behavior_for(dimension) != :ignore
  end
end

#supports_formatting_detection?(dimension) ⇒ Boolean

Can a difference in this dimension be formatting-only?

Delegates to the Dimension object’s supports_formatting_detection? flag. Falls back to false for unknown dimensions.

Parameters:

  • dimension (Symbol)

    The match dimension to check

Returns:

  • (Boolean)

    true if formatting detection should apply



57
58
59
60
# File 'lib/canon/comparison/compare_profile.rb', line 57

def supports_formatting_detection?(dimension)
  dim = dimension_for(dimension)
  dim ? dim.supports_formatting_detection? : false
end

#track_dimension?(_dimension) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/canon/comparison/compare_profile.rb', line 20

def track_dimension?(_dimension)
  true
end