Class: Erde::HashTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/erde/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashTransformer

Returns a new instance of HashTransformer.



34
35
36
# File 'lib/erde/cli.rb', line 34

def initialize(hash)
  @hash = hash
end

Instance Method Details

#to_dotObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/erde/cli.rb', line 38

def to_dot
  template = File.read(File.expand_path("../template.dot.erb", __FILE__))

  schema_string = ""
  schema_string << "digraph tables {"
  schema_string << "node [shape=plaintext rankdir=LR];"

  @hash.each_pair do |table_name, table_schema|
    renderer = ERB.new(template)
    schema_string << renderer.result(binding)

    table_schema['relations'].each_pair do |column, target|
      schema_string << "#{table_name}:#{column} -> #{target['table']}:#{target['column']};"
    end
  end

  schema_string << "}"

  schema_string
end