Class: Erde::HashTransformer
- Inherits:
-
Object
- Object
- Erde::HashTransformer
- Defined in:
- lib/erde/cli.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ HashTransformer
constructor
A new instance of HashTransformer.
- #to_dot ⇒ Object
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_dot ⇒ Object
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.("../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 |