Class: DBA::DOTPrinter

Inherits:
DiagramPrinter show all
Defined in:
lib/dba/dot_printer.rb

Instance Method Summary collapse

Methods inherited from DiagramPrinter

#initialize, #print_column, #print_diagram, #print_table_end, #print_table_start

Constructor Details

This class inherits a constructor from DBA::DiagramPrinter

Instance Method Details



10
11
12
# File 'lib/dba/dot_printer.rb', line 10

def print_end
  @io.puts '}'
end


34
35
36
# File 'lib/dba/dot_printer.rb', line 34

def print_foreign_key(table, column, other_table, other_column)
  @io.puts %{  #{table}:#{column} -> #{other_table}:#{other_column};}
end


4
5
6
7
8
# File 'lib/dba/dot_printer.rb', line 4

def print_start
  @io.puts 'digraph database {'
  @io.puts '  graph[rankdir="LR",ranksep=1.5,nodesep=0.5];'
  @io.puts '  node[shape="Mrecord",fontname="Helvetica,Arial,sans-serif"];'
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dba/dot_printer.rb', line 14

def print_table(name, schema_hash)
  label = [name]

  schema_hash.each do |column_name, info_hash|
    column_type = info_hash[:type] || info_hash[:db_type]

    if info_hash[:primary_key]
      @primary_keys[name] = column_name

      label << "{<#{column_name}>#{column_name}|#{column_type}}"
    else
      label << "{#{column_name}|<#{column_name}>#{column_type}}"
    end
  end

  label = label.join('|')

  @io.puts %{  #{name}[label="#{label}"];}
end