Class: SchemaRD::Metadata::Writer
- Inherits:
-
Object
- Object
- SchemaRD::Metadata::Writer
- Defined in:
- lib/schemard/metadata.rb
Overview
Writer for metadata yaml
Instance Method Summary collapse
-
#initialize(output_file) ⇒ Writer
constructor
A new instance of Writer.
- #save(table_name, position) ⇒ Object
- #save_all(tables) ⇒ Object
Constructor Details
#initialize(output_file) ⇒ Writer
Returns a new instance of Writer.
93 94 95 |
# File 'lib/schemard/metadata.rb', line 93 def initialize(output_file) @output_file = output_file end |
Instance Method Details
#save(table_name, position) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/schemard/metadata.rb', line 102 def save(table_name, position) hash = YAML.load_file(@output_file) || {} hash["tables"] = {} unless hash.has_key?("tables") hash["tables"] = {} unless hash["tables"].is_a?(Hash) hash["tables"][table_name] = {} unless hash["tables"][table_name] hash["tables"][table_name] = {} unless hash["tables"][table_name].is_a?(Hash) hash["tables"][table_name]["position_top"] = position["top"].to_s hash["tables"][table_name]["position_left"] = position["left"].to_s File.write(@output_file, YAML.dump(hash)) end |
#save_all(tables) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/schemard/metadata.rb', line 96 def save_all(tables) hash = tables.each_with_object({}) do |t, hash| hash[t.name] = { "position_top" => t.position["top"], "position_left" => t.position["left"] } end File.write(@output_file, YAML.dump({ "tables" => hash })) end |