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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/canon/comparison/compare_profile.rb', line 56 def normative_dimension?(dimension) # Element structure changes are ALWAYS normative return true if dimension == :element_structure # 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 other dimensions, if behavior affects equivalence, it's normative 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.
78 79 80 81 82 |
# File 'lib/canon/comparison/compare_profile.rb', line 78 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 |