Module: Canon::TreeDiff::OperationConverterHelpers::MetadataEnricher
- Defined in:
- lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb
Overview
Metadata enrichment for DiffNodes Handles path building, serialization, and attribute extraction
Class Method Summary collapse
-
.build_path(tree_node, format) ⇒ String?
Build canonical path for a TreeNode.
-
.enrich(tree_node1, tree_node2, format) ⇒ Hash
Enrich DiffNode with canonical path, serialized content, and attributes This extracts presentation-ready metadata from TreeNodes for Stage 4 rendering.
-
.extract_attributes(tree_node) ⇒ Hash?
Extract attributes from a TreeNode.
-
.serialize(tree_node) ⇒ String?
Serialize a TreeNode’s source node to string.
Class Method Details
.build_path(tree_node, format) ⇒ String?
Build canonical path for a TreeNode
34 35 36 37 38 39 |
# File 'lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb', line 34 def self.build_path(tree_node, format) return nil if tree_node.nil? Canon::Diff::PathBuilder.build(tree_node, format: format == :xml ? :document : :fragment) end |
.enrich(tree_node1, tree_node2, format) ⇒ Hash
Enrich DiffNode with canonical path, serialized content, and attributes This extracts presentation-ready metadata from TreeNodes for Stage 4 rendering
19 20 21 22 23 24 25 26 27 |
# File 'lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb', line 19 def self.enrich(tree_node1, tree_node2, format) { path: build_path(tree_node1 || tree_node2, format), serialized_before: serialize(tree_node1), serialized_after: serialize(tree_node2), attributes_before: extract_attributes(tree_node1), attributes_after: extract_attributes(tree_node2), } end |
.extract_attributes(tree_node) ⇒ Hash?
Extract attributes from a TreeNode
62 63 64 65 66 67 |
# File 'lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb', line 62 def self.extract_attributes(tree_node) return nil if tree_node.nil? # Use TreeNode's attributes directly (already normalized by adapter) tree_node.respond_to?(:attributes) ? (tree_node.attributes || {}) : {} end |
.serialize(tree_node) ⇒ String?
Serialize a TreeNode’s source node to string
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb', line 45 def self.serialize(tree_node) return nil if tree_node.nil? # Extract source node from TreeNode source = if tree_node.respond_to?(:source_node) tree_node.source_node else tree_node end Canon::Diff::NodeSerializer.serialize(source) end |