Class: Graphm::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, &block) ⇒ Graph

Returns a new instance of Graph.



10
11
12
13
14
# File 'lib/graphm/graph.rb', line 10

def initialize name=nil, &block
  @name = name
  @nodes = {}
  self.instance_eval(&block) if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/graphm/graph.rb', line 8

def name
  @name
end

#nodesObject (readonly)

Returns the value of attribute nodes.



8
9
10
# File 'lib/graphm/graph.rb', line 8

def nodes
  @nodes
end

Instance Method Details

#edge(src, dst, prop = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/graphm/graph.rb', line 20

def edge src, dst, prop={}
  src_node = node src
  dst_node = node dst

  @nodes[src].edge_to dst_node, prop
end

#final(name) ⇒ Object



40
41
42
# File 'lib/graphm/graph.rb', line 40

def final name
  node name, {:final => true}
end

#initial(name) ⇒ Object



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

def initial name
  node name, {:initial => true}
end

#node(name, prop = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/graphm/graph.rb', line 27

def node name, prop={}
  if not @nodes.include? name then
    @nodes[name] = Node.new name, prop
  else
    @nodes[name].set_prop prop
  end
  return @nodes[name]
end

#render(renderer) ⇒ Object



44
45
46
# File 'lib/graphm/graph.rb', line 44

def render renderer
  return renderer.render_graph self
end

#title(name) ⇒ Object



16
17
18
# File 'lib/graphm/graph.rb', line 16

def title name
  @name = name
end