Class: RXSD::SchemaInstance
- Inherits:
-
Object
- Object
- RXSD::SchemaInstance
- Defined in:
- lib/rxsd/translator.rb
Overview
SchemaInstance contains an array of ObjectBuilders and provides mechanism to instantiate objects from conforming to a xsd schema
Instance Attribute Summary collapse
-
#object_builders ⇒ Object
array of object builders represented by current instance.
Class Method Summary collapse
-
.builders_from_xml(node, parent = nil) ⇒ Object
Return array of ObjectBuilders parsed out of a RXSD::XML::Node.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ SchemaInstance
constructor
Create new schema instance w/ specified args.
-
#to(output_type, args = {}) ⇒ Object
translates SchemaInstance’s objects into instances of the specified output type.
Constructor Details
#initialize(args = {}) ⇒ SchemaInstance
Create new schema instance w/ specified args
103 104 105 |
# File 'lib/rxsd/translator.rb', line 103 def initialize(args = {}) @object_builders = args[:builders] if args.has_key? :builders end |
Instance Attribute Details
#object_builders ⇒ Object
array of object builders represented by current instance
84 85 86 |
# File 'lib/rxsd/translator.rb', line 84 def object_builders @object_builders end |
Class Method Details
.builders_from_xml(node, parent = nil) ⇒ Object
Return array of ObjectBuilders parsed out of a RXSD::XML::Node. Optionally specify parent ObjectBuilder to use
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rxsd/translator.rb', line 88 def self.builders_from_xml(node, parent = nil) node_builder = ObjectBuilder.new(:tag_name => node.name, :attributes => node.attrs, :parent => parent) parent.children.push node_builder unless parent.nil? || parent.children.include?(node_builder) builders = [ node_builder ] if node.text? node_builder.content = node.content else node.children.each { |c| builders += SchemaInstance.builders_from_xml(c, node_builder ) } end return builders end |
Instance Method Details
#to(output_type, args = {}) ⇒ Object
translates SchemaInstance’s objects into instances of the specified output type.
-
:output_type may be one of
-
:ruby_objects
-
Must specify :schema argument containing RXSD::XSD::Schema to use in object creation
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rxsd/translator.rb', line 111 def to(output_type, args = {}) schema = args[:schema] results = [] @object_builders.each { |ob| # probably a better way to do this at some point than invoking the copy constructors case(output_type) when :ruby_objects ob = RubyObjectBuilder.new(:builder => ob).build(schema) results.push ob end } return results end |