class Grifork::Graph::Node
Attributes
count[R]
index[RW]
Public Class Methods
add()
click to toggle source
# File lib/grifork/graph/node.rb, line 7 def add @count ||= 0 @count += 1 end
new(host, parent: nil)
click to toggle source
# File lib/grifork/graph/node.rb, line 13 def initialize(host, parent: nil) @host = host @children = [] if parent @parent = parent @level = parent.level + 1 @number = parent.children.size else @level = 0 @number = 0 end @index = self.class.count || 0 self.class.add end
Public Instance Methods
acceptable?()
click to toggle source
# File lib/grifork/graph/node.rb, line 53 def acceptable? children.size < config.branches end
add_child(child)
click to toggle source
# File lib/grifork/graph/node.rb, line 42 def add_child(child) unless acceptable? raise "Unacceptable!" end @children << child end
all_descendant_nodes()
click to toggle source
# File lib/grifork/graph/node.rb, line 57 def all_descendant_nodes @descendants = @children @descendables = @children.select { |c| c.children.size > 0 } while @descendables.size > 0 child = @descendables.shift @descendants.concat(child.children) new_descendables = child.children { |n| n.children.size > 0 } @descendables.concat(new_descendables) end @descendants end
id()
click to toggle source
# File lib/grifork/graph/node.rb, line 32 def id @id ||= -> { if parent "#{parent.id}-#{level}.#{number}" else "#{level}.#{number}" end }.call end
local?()
click to toggle source
# File lib/grifork/graph/node.rb, line 49 def local? parent ? false : true end
to_s()
click to toggle source
# File lib/grifork/graph/node.rb, line 28 def to_s "<#{index}:#{id}>" end