Class: Canon::Comparison::CompareProfile
- Inherits:
-
Object
- Object
- Canon::Comparison::CompareProfile
- 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
Instance Attribute Summary collapse
-
#match_options ⇒ Object
readonly
Returns the value of attribute match_options.
Instance Method Summary collapse
-
#affects_equivalence?(dimension) ⇒ Boolean
Should differences in this dimension affect equivalence?.
-
#initialize(match_options) ⇒ CompareProfile
constructor
A new instance of CompareProfile.
-
#normative_dimension?(dimension) ⇒ Boolean
Is a difference in this dimension normative (affects equivalence)?.
-
#supports_formatting_detection?(dimension) ⇒ Boolean
Can a difference in this dimension be formatting-only?.
-
#track_dimension?(_dimension) ⇒ Boolean
Should DiffNodes be created for differences in this dimension?.
Constructor Details
#initialize(match_options) ⇒ CompareProfile
Returns a new instance of CompareProfile.
16 17 18 |
# File 'lib/canon/comparison/compare_profile.rb', line 16 def initialize() @match_options = end |
Instance Attribute Details
#match_options ⇒ Object (readonly)
Returns the value of attribute match_options.
13 14 15 |
# File 'lib/canon/comparison/compare_profile.rb', line 13 def @match_options end |
Instance Method Details
#affects_equivalence?(dimension) ⇒ Boolean
Should differences in this dimension affect equivalence?
This determines the return value of the comparison:
-
true: differences make documents non-equivalent
-
false: differences are informative only
41 42 43 44 45 46 47 48 |
# File 'lib/canon/comparison/compare_profile.rb', line 41 def affects_equivalence?(dimension) behavior = behavior_for(dimension) # :strict → affects equivalence # :normalize → might affect (if normalization fails) # :ignore → does NOT affect equivalence behavior != :ignore end |
#normative_dimension?(dimension) ⇒ Boolean
Is a difference in this dimension normative (affects equivalence)?
This is used by DiffClassifier to determine the normative flag.
Normative rules by dimension:
-
structural_whitespace: only :strict is normative (:normalize and :ignore are informative)
-
all other dimensions: normative unless behavior is :ignore
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/canon/comparison/compare_profile.rb', line 60 def normative_dimension?(dimension) # Structural whitespace with :normalize or :ignore behavior is INFORMATIVE # Only :strict mode makes whitespace normative if dimension == :structural_whitespace behavior = behavior_for(dimension) return behavior == :strict end # For all other dimensions, normative if behavior affects equivalence affects_equivalence?(dimension) end |
#supports_formatting_detection?(dimension) ⇒ Boolean
Can a difference in this dimension be formatting-only?
This determines whether FormattingDetector should be applied. Only text/content dimensions can have formatting-only differences.
79 80 81 82 83 |
# File 'lib/canon/comparison/compare_profile.rb', line 79 def supports_formatting_detection?(dimension) # Only text_content and structural_whitespace can have formatting-only diffs # Comments are policy-based (strict/ignore), not formatting-based %i[text_content structural_whitespace].include?(dimension) end |
#track_dimension?(_dimension) ⇒ Boolean
Should DiffNodes be created for differences in this dimension?
In verbose mode, we want to track ALL differences for reporting. In non-verbose mode, we only need to track normative differences.
27 28 29 30 31 |
# File 'lib/canon/comparison/compare_profile.rb', line 27 def track_dimension?(_dimension) # Always track dimensions that affect equivalence # In verbose mode, also track informative dimensions true end |