Class: Graph::Node

Inherits:
Thingy
  • Object
show all
Defined in:
lib/graph.rb

Overview

Nodes in the graph.

Instance Attribute Summary collapse

Attributes inherited from Thingy

#attributes, #graph

Instance Method Summary collapse

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.



456
457
458
459
# File 'lib/graph.rb', line 456

def initialize graph, name
  super graph
  self.name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



440
441
442
# File 'lib/graph.rb', line 440

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.



465
466
467
468
# File 'lib/graph.rb', line 465

def >> name
  self[name] # creates node and edge
  self
end

#[](dep_name) ⇒ Object

Returns the edge between self and dep_name.



475
476
477
# File 'lib/graph.rb', line 475

def [] dep_name
  graph.edges[name][dep_name]
end

#connected?Boolean

Returns:

  • (Boolean)


442
443
444
445
446
447
# File 'lib/graph.rb', line 442

def connected?
  node = self.name
  edges = graph.edges

  edges.include?(name) or edges.any? { |from, deps| deps.include? name }
end

#orphan?Boolean

Returns:

  • (Boolean)


449
450
451
# File 'lib/graph.rb', line 449

def orphan?
  not connected?
end

#to_sObject

Returns the node in dot syntax.



482
483
484
485
486
487
488
# File 'lib/graph.rb', line 482

def to_s
  if self.attributes? then
    "%-20p [ %-20s ]" % [name, attributes.join(',')]
  else
    "#{name.inspect}"
  end
end