Class: Graph::Node
Overview
Nodes in the graph.
Instance Attribute Summary collapse
-
#name ⇒ Object
:nodoc:.
Attributes inherited from Thingy
Instance Method Summary collapse
-
#>>(name) ⇒ Object
(also: #<<)
Create a new node with
nameand an edge between them pointing from self to the new node. -
#[](dep_name) ⇒ Object
Returns the edge between self and
dep_name. -
#connected? ⇒ Boolean
Is this node connected to the graph?.
-
#initialize(graph, name) ⇒ Node
constructor
Create a new Node.
-
#orphan? ⇒ Boolean
Is this node an orphan? (ie, not connected?).
-
#to_s ⇒ Object
Returns the node in dot syntax.
Methods inherited from Thingy
#attributes?, #initialize_copy, #label
Constructor Details
#initialize(graph, name) ⇒ Node
Create a new Node. Takes a parent graph and a name.
590 591 592 593 |
# File 'lib/graph.rb', line 590 def initialize graph, name super graph self.name = name end |
Instance Attribute Details
Instance Method Details
#>>(name) ⇒ Object Also known as: <<
Create a new node with name and an edge between them pointing from self to the new node.
599 600 601 602 |
# File 'lib/graph.rb', line 599 def >> name self[name] # creates node and edge self end |
#[](dep_name) ⇒ Object
Returns the edge between self and dep_name.
609 610 611 |
# File 'lib/graph.rb', line 609 def [] dep_name graph.edges[name][dep_name] end |
#connected? ⇒ Boolean
Is this node connected to the graph?
574 575 576 577 578 |
# File 'lib/graph.rb', line 574 def connected? edges = graph.edges edges.include?(name) or edges.any? { |from, deps| deps.include? name } end |
#orphan? ⇒ Boolean
Is this node an orphan? (ie, not connected?)
583 584 585 |
# File 'lib/graph.rb', line 583 def orphan? not connected? end |
#to_s ⇒ Object
Returns the node in dot syntax.
616 617 618 619 620 621 622 |
# File 'lib/graph.rb', line 616 def to_s if self.attributes? then "%-20p [ %-20s ]" % [name, attributes.join(',')] else "#{name.inspect}" end end |