Class: Graphviz::Node

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

Direct Known Subclasses

EdgeNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, name, attributes = {}) ⇒ Node

Returns a new instance of Node.



25
26
27
28
29
30
31
32
33
# File 'lib/graphviz/graph.rb', line 25

def initialize(graph, name, attributes = {})
	@graph = graph
	@graph.nodes[name] = self
	
	@name = name
	@attributes = attributes
	
	@edges = []
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



39
40
41
# File 'lib/graphviz/graph.rb', line 39

def attributes
  @attributes
end

#edgesObject (readonly)

Returns the value of attribute edges.



38
39
40
# File 'lib/graphviz/graph.rb', line 38

def edges
  @edges
end

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'lib/graphviz/graph.rb', line 35

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



36
37
38
# File 'lib/graphviz/graph.rb', line 36

def options
  @options
end

Instance Method Details

#add_node(name, options = {}) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/graphviz/graph.rb', line 53

def add_node(name, options = {})
	node = Node.new(@graph, name, options)
	
	connect(node)
	
	return node
end

#connect(destination, options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/graphviz/graph.rb', line 41

def connect(destination, options = {})
	edge = Edge.new(@graph, self, destination, options)
	
	@edges << edge
	
	return edge
end

#connected?(node) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/graphviz/graph.rb', line 49

def connected?(node)
	return @edges.find{|edge| edge.destination == node}
end