Module: Canon::Comparison::XmlComparatorHelpers::ChildComparison
- Defined in:
- lib/canon/comparison/xml_comparator/child_comparison.rb
Overview
Child comparison service for XML nodes
Handles comparison of child nodes using both semantic matching (ElementMatcher) and simple positional comparison. Delegates back to the comparator for individual node comparisons.
This module encapsulates the complex child comparison logic, making the main XmlComparator cleaner and more maintainable.
Class Method Summary collapse
-
.compare(node1, node2, comparator, opts, child_opts, diff_children, differences) ⇒ Integer
Compare children of two nodes using semantic matching.
Class Method Details
.compare(node1, node2, comparator, opts, child_opts, diff_children, differences) ⇒ Integer
Compare children of two nodes using semantic matching
Uses ElementMatcher to pair children semantically (by identity attributes or position), then compares matched pairs and detects position changes.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/canon/comparison/xml_comparator/child_comparison.rb', line 29 def compare(node1, node2, comparator, opts, child_opts, diff_children, differences) children1 = comparator.send(:filter_children, node1.children, opts) children2 = comparator.send(:filter_children, node2.children, opts) # Quick check: if both have no children, they're equivalent return Comparison::EQUIVALENT if children1.empty? && children2.empty? # Check if we can use ElementMatcher (requires Canon::Xml::DataModel nodes) if can_use_element_matcher?(children1, children2) use_element_matcher_comparison(children1, children2, node1, comparator, opts, child_opts, diff_children, differences) else use_positional_comparison(children1, children2, node1, comparator, opts, child_opts, diff_children, differences) end end |