Class: Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



5
6
7
# File 'lib/peekdb/graph.rb', line 5

def initialize
  @dwg = GraphViz.new(:G, :type => :digraph)
end

Instance Attribute Details

#dwgObject (readonly)

Returns the value of attribute dwg.



3
4
5
# File 'lib/peekdb/graph.rb', line 3

def dwg
  @dwg
end

Instance Method Details

#build(name, tables, relations) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/peekdb/graph.rb', line 9

def build(name, tables, relations)
  config_graph(name)
  config_nodes
  config_edges

  tables.each do |table|
    @dwg.add_nodes(table)
  end

  relations.each do |relation|
    @dwg.add_edges(relation[1], relation[3])
  end
end

#output(name, format) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/peekdb/graph.rb', line 23

def output(name, format)
  case format
  when :pdf, nil
    filename = "#{name}.pdf"
    @dwg.output(:pdf => "#{filename}")
    puts "... Writing output #{filename}"
  when :dot
    filename = "#{name}.dot"
    @dwg.output(:dot => filename)
    puts "... Writing output #{filename}"
  else
    raise ArgumentError.new("Unknown output format #{format}")
    exit(1)
  end
end