Class: Graph::Node
Overview
Nodes in the graph.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Thingy
Instance Method Summary collapse
-
#>>(name) ⇒ Object
(also: #<<)
Create a new node with
name
and an edge between them pointing from self to the new node. -
#[](dep_name) ⇒ Object
Returns the edge between self and
dep_name
. - #connected? ⇒ Boolean
-
#initialize(graph, name) ⇒ Node
constructor
Create a new Node.
- #orphan? ⇒ Boolean
-
#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.
509 510 511 512 |
# File 'lib/graph.rb', line 509 def initialize graph, name super graph self.name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
493 494 495 |
# File 'lib/graph.rb', line 493 def name @name end |
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.
518 519 520 521 |
# File 'lib/graph.rb', line 518 def >> name self[name] # creates node and edge self end |
#[](dep_name) ⇒ Object
Returns the edge between self and dep_name
.
528 529 530 |
# File 'lib/graph.rb', line 528 def [] dep_name graph.edges[name][dep_name] end |
#connected? ⇒ Boolean
495 496 497 498 499 500 |
# File 'lib/graph.rb', line 495 def connected? node = self.name edges = graph.edges edges.include?(name) or edges.any? { |from, deps| deps.include? name } end |
#orphan? ⇒ Boolean
502 503 504 |
# File 'lib/graph.rb', line 502 def orphan? not connected? end |
#to_s ⇒ Object
Returns the node in dot syntax.
535 536 537 538 539 540 541 |
# File 'lib/graph.rb', line 535 def to_s if self.attributes? then "%-20p [ %-20s ]" % [name, attributes.join(',')] else "#{name.inspect}" end end |