Class: Tinydot::Digraph

Inherits:
Object
  • Object
show all
Defined in:
lib/tinydot/digraph.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Digraph

Returns a new instance of Digraph.



5
6
7
8
# File 'lib/tinydot/digraph.rb', line 5

def initialize(name)
  @name = name
  @nodes = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/tinydot/digraph.rb', line 16

def method_missing(name, *args)
  node = @nodes.select { |node| node.name == name }.first
  if node.nil?
    node = Node.new(name)
    @nodes << node
  end
  node
end

Instance Method Details

#to_dotObject



10
11
12
13
14
# File 'lib/tinydot/digraph.rb', line 10

def to_dot
  template_path = Tinydot.root_path.join("lib/tinydot/template.dot.erb")
  template = ERB.new(template_path.read, nil, "-")
  template.result(binding)
end