class CIMI::Model::Schema::Array

Attributes

struct[RW]

Public Class Methods

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

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

# File lib/cimi/models/schema.rb, line 157
def initialize(name, opts = {}, &block)
  unless opts[:xml_name]
    opts[:xml_name] = name.to_s.singularize.camelize.uncapitalize
  end
  super(name, opts)
  @struct = Struct.new(name, opts, &block)
end

Public Instance Methods

from_json(json, model) click to toggle source
# File lib/cimi/models/schema.rb, line 169
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/models/schema.rb, line 165
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/models/schema.rb, line 178
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/models/schema.rb, line 173
def to_xml(model, xml)
  ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
  xml[xml_name] = ary unless ary.empty?
end