# File lib/cimi/models/schema.rb, line 191 def initialize(name, opts = {}, &block) opts[:json_name] = name.to_s.pluralize unless opts[:json_name] super(name, opts) end
# File lib/cimi/models/schema.rb, line 203 def from_json(json, model) model[name] = json[json_name] || {} end
# File lib/cimi/models/schema.rb, line 196 def from_xml(xml, model) model[name] = (xml[xml_name] || []).inject({}) do |result, item| result[item["name"]] = item["content"] result end end
# File lib/cimi/models/schema.rb, line 212 def to_json(model, json) if model[name] && ! model[name].empty? json[json_name] = model[name] end end
# File lib/cimi/models/schema.rb, line 207 def to_xml(model, xml) ary = (model[name] || {}).map { |k, v| { "name" => k, "content" => v } } xml[xml_name] = ary unless ary.empty? end