Class: TreeDiff::Node
- Inherits:
-
Struct
- Object
- Struct
- TreeDiff::Node
- Defined in:
- lib/tree_diff/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#edge ⇒ Object
Returns the value of attribute edge.
-
#name ⇒ Object
Returns the value of attribute name.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #accept(visitor) ⇒ Object
- #all_equal? ⇒ Boolean
- #hash ⇒ Object
- #merge(other) ⇒ Object
- #to_dot ⇒ Object
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
2 3 4 |
# File 'lib/tree_diff/node.rb', line 2 def children @children end |
#edge ⇒ Object
Returns the value of attribute edge
2 3 4 |
# File 'lib/tree_diff/node.rb', line 2 def edge @edge end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/tree_diff/node.rb', line 2 def name @name end |
#source ⇒ Object
Returns the value of attribute source
2 3 4 |
# File 'lib/tree_diff/node.rb', line 2 def source @source end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
3 4 5 |
# File 'lib/tree_diff/node.rb', line 3 def == other name == other.name && edge == other.edge end |
#accept(visitor) ⇒ Object
25 26 27 |
# File 'lib/tree_diff/node.rb', line 25 def accept visitor visitor.visit(self) end |
#all_equal? ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tree_diff/node.rb', line 35 def all_equal? eql = Class.new { attr_accessor :equal def initialize root @root = root @equal = true end def accept target target.accept(self) end def visit node return unless @equal @equal = node.source == @root.source node.children.each { |c| c.accept(self) } end }.new(self) eql.accept(self) eql.equal end |
#hash ⇒ Object
8 9 10 |
# File 'lib/tree_diff/node.rb', line 8 def hash "#{name}#{edge}".hash end |
#merge(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tree_diff/node.rb', line 12 def merge other raise unless other.name == name diff = (children - other.children) + (other.children - children) left_same = (children & other.children) merged = left_same.map do |node| node.merge(other.children.find { |n| n == node }) end Node.new(name, edge, diff + merged, source + other.source) end |
#to_dot ⇒ Object
29 30 31 32 33 |
# File 'lib/tree_diff/node.rb', line 29 def to_dot dv = DotVisitor.new(self) dv.accept(self) dv end |