Module: XmlSchemaMapper
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/xml_schema_mapper.rb,
lib/xml_schema_mapper/parser.rb,
lib/xml_schema_mapper/builder.rb,
lib/xml_schema_mapper/element.rb,
lib/xml_schema_mapper/version.rb,
lib/xml_schema_mapper/test_builder.rb,
lib/xml_schema_mapper/namespace_resolver.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Builder, Element, NamespaceResolver, Parser, TestBuilder
Constant Summary
collapse
- VERSION =
'0.0.12'
Instance Method Summary
collapse
Instance Method Details
#[](key) ⇒ Object
89
90
91
|
# File 'lib/xml_schema_mapper.rb', line 89
def [](key)
send(key)
end
|
#[]=(key, val) ⇒ Object
93
94
95
|
# File 'lib/xml_schema_mapper.rb', line 93
def []=(key, val)
send(:"#{key}=", val)
end
|
#accept(visitor, *args) ⇒ Object
97
98
99
|
# File 'lib/xml_schema_mapper.rb', line 97
def accept(visitor, *args)
visitor.visit(self, *args)
end
|
#element_names ⇒ Object
117
118
119
|
# File 'lib/xml_schema_mapper.rb', line 117
def element_names
elements.keys
end
|
#element_values ⇒ Object
121
122
123
|
# File 'lib/xml_schema_mapper.rb', line 121
def element_values
elements.values
end
|
#elements ⇒ Object
125
126
127
128
129
|
# File 'lib/xml_schema_mapper.rb', line 125
def elements
type.elements.values.inject({}) do |hash, element|
hash.merge element.name.underscore.to_sym => send(element.name.underscore.to_sym)
end
end
|
#find_root_namespace(document) ⇒ Object
144
145
146
147
148
|
# File 'lib/xml_schema_mapper.rb', line 144
def find_root_namespace(document)
namespaces = namespace_resolver || schema.namespaces
ns = namespaces.find_by_href (global_element || _type).namespace
document.root.add_namespace_definition(ns.prefix, ns.href)
end
|
#global_element ⇒ Object
159
160
161
|
# File 'lib/xml_schema_mapper.rb', line 159
def global_element
schema.elements.values.find { |e| e.type.name == _type.name }
end
|
#namespace_resolver ⇒ Object
150
151
152
153
154
155
156
157
|
# File 'lib/xml_schema_mapper.rb', line 150
def namespace_resolver
case
when self.class.namespace_resolver_class
self.class.namespace_resolver_class.new(schema.namespaces)
when XmlSchemaMapper.namespace_resolver_class
XmlSchemaMapper.namespace_resolver_class.new(schema.namespaces)
end
end
|
#schema ⇒ Object
113
114
115
|
# File 'lib/xml_schema_mapper.rb', line 113
def schema
self.class.schema
end
|
#simple? ⇒ Boolean
101
102
103
|
# File 'lib/xml_schema_mapper.rb', line 101
def simple?
_type.simple?
end
|
#to_xml(options = {}) ⇒ Object
131
132
133
|
# File 'lib/xml_schema_mapper.rb', line 131
def to_xml(options = {})
xml_document.root.to_xml({:encoding => 'UTF-8'}.merge(options))
end
|
#type ⇒ Object
109
110
111
|
# File 'lib/xml_schema_mapper.rb', line 109
def type
self.class.type
end
|
#values ⇒ Object
105
106
107
|
# File 'lib/xml_schema_mapper.rb', line 105
def values
_type.facets.map &:value
end
|
#xml_document ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/xml_schema_mapper.rb', line 135
def xml_document
document = XmlSchemaMapper::Builder.create_document(_type)
document.root.namespace = find_root_namespace(document)
builder = XmlSchemaMapper::Builder.new(self, document.root, namespace_resolver)
builder.build
builder.document
end
|