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
-
#attributes_after ⇒ Object
Returns the value of attribute attributes_after.
-
#attributes_before ⇒ Object
Returns the value of attribute attributes_before.
-
#dimension ⇒ Object
Returns the value of attribute dimension.
-
#formatting ⇒ Object
Returns the value of attribute formatting.
-
#node1 ⇒ Object
readonly
Returns the value of attribute node1.
-
#node2 ⇒ Object
readonly
Returns the value of attribute node2.
-
#normative ⇒ Object
Returns the value of attribute normative.
-
#path ⇒ Object
Returns the value of attribute path.
-
#reason ⇒ Object
Returns the value of attribute reason.
-
#serialized_after ⇒ Object
Returns the value of attribute serialized_after.
-
#serialized_before ⇒ Object
Returns the value of attribute serialized_before.
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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/canon/diff/diff_node.rb', line 33 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
#attributes_after ⇒ Object
Returns the value of attribute attributes_after.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def attributes_after @attributes_after end |
#attributes_before ⇒ Object
Returns the value of attribute attributes_before.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def attributes_before @attributes_before end |
#dimension ⇒ Object
Returns the value of attribute dimension.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def dimension @dimension end |
#formatting ⇒ Object
Returns the value of attribute formatting.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def formatting @formatting end |
#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 |
#normative ⇒ Object
Returns the value of attribute normative.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def normative @normative end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def path @path end |
#reason ⇒ Object
Returns the value of attribute reason.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def reason @reason end |
#serialized_after ⇒ Object
Returns the value of attribute serialized_after.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def serialized_after @serialized_after end |
#serialized_before ⇒ Object
Returns the value of attribute serialized_before.
14 15 16 |
# File 'lib/canon/diff/diff_node.rb', line 14 def serialized_before @serialized_before end |
Instance Method Details
#==(other) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/canon/diff/diff_node.rb', line 88 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
68 69 70 |
# File 'lib/canon/diff/diff_node.rb', line 68 def formatting? @formatting == true end |
#informative? ⇒ Boolean
Formatting-only diffs are never informative
60 61 62 63 64 |
# File 'lib/canon/diff/diff_node.rb', line 60 def informative? return false if formatting? @normative == false end |
#normative? ⇒ Boolean
Formatting-only diffs are never normative
52 53 54 55 56 |
# File 'lib/canon/diff/diff_node.rb', line 52 def normative? return false if formatting? @normative == true end |
#to_h ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/canon/diff/diff_node.rb', line 72 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 |