Class: Graph::Node

Inherits:
Thingy 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.



579
580
581
582
# File 'lib/graph.rb', line 579

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

Instance Attribute Details

#nameObject

:nodoc:



558
559
560
# File 'lib/graph.rb', line 558

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.



588
589
590
591
# File 'lib/graph.rb', line 588

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

#[](dep_name) ⇒ Object

Returns the edge between self and dep_name.



598
599
600
# File 'lib/graph.rb', line 598

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

#connected?Boolean

Is this node connected to the graph?

Returns:

  • (Boolean)


563
564
565
566
567
# File 'lib/graph.rb', line 563

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?)

Returns:

  • (Boolean)


572
573
574
# File 'lib/graph.rb', line 572

def orphan?
  not connected?
end

#to_sObject

Returns the node in dot syntax.



605
606
607
608
609
610
611
# File 'lib/graph.rb', line 605

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