Class: TreeDiff::Unify
- Inherits:
-
Object
- Object
- TreeDiff::Unify
- Defined in:
- lib/tree_diff/unify.rb
Instance Method Summary collapse
- #accept(target) ⇒ Object
-
#initialize(source) ⇒ Unify
constructor
A new instance of Unify.
- #visit(node) ⇒ Object
Constructor Details
#initialize(source) ⇒ Unify
Returns a new instance of Unify.
3 4 5 |
# File 'lib/tree_diff/unify.rb', line 3 def initialize source @source = source end |
Instance Method Details
#accept(target) ⇒ Object
7 8 9 |
# File 'lib/tree_diff/unify.rb', line 7 def accept target target.accept(self) end |
#visit(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tree_diff/unify.rb', line 11 def visit node children = (node.children || []).find_all { |c| !c.text? && c.respond_to?(:accept) } edge = node.parent.children.find_all { |c| !c.text? && c.respond_to?(:accept) }.index(node) Node.new( node.name, edge, children.map { |child| child.accept(self) }, [@source] ) end |