Parent

Class/Module Index [+]

Quicksearch

CIMI::Model::Schema::Attribute

Attributes describe how we extract values from XML/JSON

Attributes

json_name[R]
name[R]
xml_name[R]

Public Class Methods

new(name, opts = {}) click to toggle source
# File lib/cimi/model/schema.rb, line 26
def initialize(name, opts = {})
  @name = name
  @xml_name = (opts[:xml_name] || name).to_s.camelize(true)
  @json_name = (opts[:json_name] || name).to_s.camelize(true)
end

Public Instance Methods

from_json(json, model) click to toggle source
# File lib/cimi/model/schema.rb, line 36
def from_json(json, model)
  model[@name] = json[@json_name]
end
from_xml(xml, model) click to toggle source
# File lib/cimi/model/schema.rb, line 32
def from_xml(xml, model)
  model[@name] = xml[@xml_name].first if xml.has_key?(@xml_name)
end
to_json(model, json) click to toggle source
# File lib/cimi/model/schema.rb, line 44
def to_json(model, json)
  json[@json_name] = model[@name] if model and model[@name]
end
to_xml(model, xml) click to toggle source
# File lib/cimi/model/schema.rb, line 40
def to_xml(model, xml)
  xml[@xml_name] = [model[@name]] if model[@name]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.