Class: GraphViz::DSL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ DSL

Create a new graph



7
8
9
10
# File 'lib/graphviz/dsl.rb', line 7

def initialize(name, options = {}, &block)
   @graph = GraphViz.new(name, options)
   instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphviz/dsl.rb', line 12

def method_missing(sym, *args, &block) #:nodoc:
   return @graph.get_graph(sym.to_s) unless @graph.get_graph(sym.to_s).nil?
   return @graph.get_node(sym.to_s) unless @graph.get_node(sym.to_s).nil?
   if(@graph.respond_to?(sym, true))
      @graph.send(sym, *args)
   elsif(block)
      @graph.add_graph(GraphViz::DSL.new(sym, { :parent => @graph, :type => @graph.type }, &block).graph)
   else
      @graph.add_nodes(sym.to_s, *args)
   end
end

Instance Attribute Details

#graphObject

Returns the value of attribute graph.



4
5
6
# File 'lib/graphviz/dsl.rb', line 4

def graph
  @graph
end

Instance Method Details

#e(*args) ⇒ Object

Create edges



31
32
33
34
35
36
37
38
39
# File 'lib/graphviz/dsl.rb', line 31

def e(*args)
   e = nil
   last = args.shift
   while current = args.shift
      e = @graph.add_edges(last, current)
      last = current
   end
   return e
end

#n(name) ⇒ Object

Add a new node



25
26
27
28
# File 'lib/graphviz/dsl.rb', line 25

def n(name)
   return @graph.get_node(name) unless @graph.get_node(name.to_s).nil?
   @graph.add_nodes(name)
end

#output(options = {}) ⇒ Object

Generate output



48
49
50
# File 'lib/graphviz/dsl.rb', line 48

def output(options = {})
   @graph.output(options)
end

#subgraph(name, &block) ⇒ Object Also known as: cluster

Add a subgraph



42
43
44
# File 'lib/graphviz/dsl.rb', line 42

def subgraph(name, &block)
   @graph.add_graph(GraphViz::DSL.new(name, { :parent => @graph, :type => @graph.type }, &block).graph)
end