Class/Module Index [+]

Quicksearch

CIMI::Model::Schema::Hash

Public Class Methods

new(name, opts = {}, &block) click to toggle source
# File lib/cimi/model/schema.rb, line 176
def initialize(name, opts = {}, &block)
  opts[:json_name] = name.to_s.pluralize unless opts[:json_name]
  super(name, opts)
  @struct = Struct.new(name, opts, &block)
end

Public Instance Methods

from_json(json, model) click to toggle source
# File lib/cimi/model/schema.rb, line 186
def from_json(json, model)
  model[name] = (json[json_name] || {}).inject([]) do |result,item|
    result << @struct.convert_from_json({ 'name' => item[0], 'value' => item[1] })
  end
end
from_xml(xml, model) click to toggle source
# File lib/cimi/model/schema.rb, line 182
def from_xml(xml, model)
  model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
end
to_json(model, json) click to toggle source
# File lib/cimi/model/schema.rb, line 197
def to_json(model, json)
  ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
  json[json_name] = ary.inject({}) { |result, item| result[item['name']] = item['value']; result } unless ary.empty?
end
to_xml(model, xml) click to toggle source
# File lib/cimi/model/schema.rb, line 192
def to_xml(model, xml)
  ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
  xml[xml_name] = ary unless ary.empty?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.