class CIMI::Model::Schema::Hash

Public Class Methods

new(name, opts = {}, &block) click to toggle source
Calls superclass method CIMI::Model::Schema::Attribute.new
# File lib/cimi/models/schema.rb, line 262
def initialize(name, opts = {}, &block)
  opts[:json_name] = name.to_s.pluralize unless opts[:json_name]
  super(name, opts)
end

Public Instance Methods

from_json(json, model) click to toggle source
# File lib/cimi/models/schema.rb, line 274
def from_json(json, model)
  model[name] = json[json_name] || {}
end
from_xml(xml, model) click to toggle source
# File lib/cimi/models/schema.rb, line 267
def from_xml(xml, model)
  model[name] = (xml[xml_name] || []).inject({}) do |result, item|
    result[item["key"]] = item["content"]
    result
  end
end
to_json(model, json) click to toggle source
# File lib/cimi/models/schema.rb, line 283
def to_json(model, json)
  h = extract(model)
  json[json_name] = h unless h.empty?
end
to_xml(model, xml) click to toggle source
# File lib/cimi/models/schema.rb, line 278
def to_xml(model, xml)
  mapped = extract(model).map { |k, v| { "key" => k, "content" => v } }
  xml[xml_name] = mapped unless mapped.empty?
end