Class: RXSD::Resolver
- Inherits:
-
Object
- Object
- RXSD::Resolver
- Defined in:
- lib/rxsd/resolver.rb
Overview
Resolves xsd relationships, used internally
Class Method Summary collapse
-
.node_objects(node_obj, args = {}) ⇒ Object
return hash of xsd types -> array of type instances for all nodes underneath given node_obj (inclusive).
-
.resolve_nodes(schema) ⇒ Object
resolves hanging node relationships for specified schema.
Class Method Details
.node_objects(node_obj, args = {}) ⇒ Object
return hash of xsd types -> array of type instances for all nodes underneath given node_obj (inclusive)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rxsd/resolver.rb', line 15 def self.node_objects(node_obj, args = {}) if args.has_key? :node_objs node_objs = args[:node_objs] else # TODO auto generate keys from classes defined under the XSD module node_objs = {XSD::Attribute => [], XSD::AttributeGroup => [], XSD::Choice => [], XSD::ComplexContent => [], XSD::ComplexType => [], XSD::Element => [], XSD::Extension => [], XSD::Group => [], XSD::List => [], XSD::Restriction => [], XSD::Schema => [], XSD::Sequence => [], XSD::SimpleContent => [], XSD::SimpleType => []} unless node_obj.nil? node_objs[node_obj.class].push node_obj end end unless node_obj.nil? node_obj.children.each{ |noc| unless noc.nil? || node_objs[noc.class].include?(noc) node_objs[noc.class].push noc node_objs = node_objects(noc, :node_objs => node_objs) # might be better to do a breadth first traversal instead? end } end node_objs end |
.resolve_nodes(schema) ⇒ Object
resolves hanging node relationships for specified schema
43 44 45 46 47 48 49 50 |
# File 'lib/rxsd/resolver.rb', line 43 def self.resolve_nodes(schema) node_objs = node_objects(schema) node_objs.each { |xsd_class, nobjs| nobjs.each{ |no| no.resolve(node_objs) } } end |