Class: Graph
- Inherits:
-
Object
- Object
- Graph
- Defined in:
- lib/peekdb/graph.rb
Instance Attribute Summary collapse
-
#dwg ⇒ Object
readonly
Returns the value of attribute dwg.
Instance Method Summary collapse
- #build(name, tables, relations) ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #output(name, format) ⇒ Object
Constructor Details
#initialize ⇒ Graph
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
#dwg ⇒ Object (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 |