Class/Module Index [+]

Quicksearch

CIMI::Model::Schema::Array

Public Class Methods

new(name, opts = {}, &block) click to toggle source

For an array :things, we collect all <thing/> elements (XmlSimple actually does the collecting)

# File lib/cimi/model/schema.rb, line 149
def initialize(name, opts = {}, &block)
  opts[:xml_name] = name.to_s.singularize unless opts[:xml_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 159
def from_json(json, model)
  model[name] = (json[json_name] || []).map { |elt| @struct.convert_from_json(elt) }
end
from_xml(xml, model) click to toggle source
# File lib/cimi/model/schema.rb, line 155
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 168
def to_json(model, json)
  ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
  json[json_name] = ary unless ary.empty?
end
to_xml(model, xml) click to toggle source
# File lib/cimi/model/schema.rb, line 163
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.