Class: Canon::Diff::DiffNode
- Inherits:
-
Object
- Object
- Canon::Diff::DiffNode
- Defined in:
- lib/canon/diff/diff_node.rb
Overview
Represents a semantic difference between two nodes in a comparison tree This is created during the Comparison Layer and carries information about which dimension caused the difference and whether it’s normative or informative
DiffNode is library-agnostic - it works with data extracted from nodes, not the raw node references themselves. This allows Canon to work with any parsing library (Nokogiri, Moxml, etc.) without being tied to it.
Instance Attribute Summary collapse
-
#node1 ⇒ Object
readonly
Returns the value of attribute node1.
-
#node2 ⇒ Object
readonly
Returns the value of attribute node2.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#formatting? ⇒ Boolean
Formatting diffs are whitespace/line break differences with no semantic meaning.
-
#informative? ⇒ Boolean
Formatting-only diffs are never informative.
-
#initialize(node1:, node2:, dimension:, reason:, path: nil, serialized_before: nil, serialized_after: nil, attributes_before: nil, attributes_after: nil) ⇒ DiffNode
constructor
A new instance of DiffNode.
-
#normative? ⇒ Boolean
Formatting-only diffs are never normative.
- #to_h ⇒ Object
Constructor Details
#initialize(node1:, node2:, dimension:, reason:, path: nil, serialized_before: nil, serialized_after: nil, attributes_before: nil, attributes_after: nil) ⇒ DiffNode
Returns a new instance of DiffNode.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/canon/diff/diff_node.rb', line 37 def initialize(node1:, node2:, dimension:, reason:, path: nil, serialized_before: nil, serialized_after: nil, attributes_before: nil, attributes_after: nil) @node1 = node1 @node2 = node2 @dimension = dimension @reason = reason @normative = nil # Will be set by DiffClassifier @formatting = nil # Will be set by DiffClassifier # Enriched metadata (optional, populated by PathBuilder and NodeSerializer) @path = path @serialized_before = serialized_before @serialized_after = serialized_after @attributes_before = attributes_before @attributes_after = attributes_after end |
Instance Attribute Details
#node1 ⇒ Object (readonly)
Returns the value of attribute node1.
13 14 15 |
# File 'lib/canon/diff/diff_node.rb', line 13 def node1 @node1 end |
#node2 ⇒ Object (readonly)
Returns the value of attribute node2.
13 14 15 |
# File 'lib/canon/diff/diff_node.rb', line 13 def node2 @node2 end |
Instance Method Details
#==(other) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/canon/diff/diff_node.rb', line 92 def ==(other) other.is_a?(DiffNode) && node1 == other.node1 && node2 == other.node2 && dimension == other.dimension && reason == other.reason && normative == other.normative && formatting == other.formatting # Note: path and serialized content are not part of equality # since they're derived from nodes, not independent properties end |
#formatting? ⇒ Boolean
Formatting diffs are whitespace/line break differences with no semantic meaning
72 73 74 |
# File 'lib/canon/diff/diff_node.rb', line 72 def formatting? @formatting == true end |
#informative? ⇒ Boolean
Formatting-only diffs are never informative
64 65 66 67 68 |
# File 'lib/canon/diff/diff_node.rb', line 64 def informative? return false if formatting? @normative == false end |
#normative? ⇒ Boolean
Formatting-only diffs are never normative
56 57 58 59 60 |
# File 'lib/canon/diff/diff_node.rb', line 56 def normative? return false if formatting? @normative == true end |
#to_h ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/canon/diff/diff_node.rb', line 76 def to_h { node1: node1, node2: node2, dimension: dimension, reason: reason, normative: normative, formatting: formatting, path: path, serialized_before: serialized_before, serialized_after: serialized_after, attributes_before: attributes_before, attributes_after: attributes_after, } end |