lib/xsd_reader/shared.rb in xsd-reader-0.2.0 vs lib/xsd_reader/shared.rb in xsd-reader-0.3.0
- old
+ new
@@ -47,25 +47,44 @@
#
# attribute properties
#
def name
- node.attributes['name'].value
+ name_local || name_referenced
end
+ def name_local
+ node.attributes['name'] ? node.attributes['name'].value : nil
+ end
+
+ def name_referenced
+ referenced_element ? referenced_element.name : nil
+ end
+
+ def ref
+ node.attributes['ref'] ? node.attributes['ref'].value : nil
+ end
+
+ def referenced_element
+ ref && schema ? schema.elements.find{|el| el.name == ref} : nil
+ end
+
+
def type
- node.attributes['type'] ? node.attributes['type'].value : nil
+ type = node.attributes['type'] ? node.attributes['type'].value : nil
+ type || (referenced_element ? referenced_element.type : nil)
end
def type_name
type ? type.split(':').last : nil
end
def type_namespace
type ? type.split(':').first : nil
end
+
# base stuff belongs to extension type objects only, but let's be flexible
def base
node.attributes['base'] ? node.attributes['base'].value : nil
end
@@ -75,10 +94,11 @@
def base_namespace
base ? base.split(':').first : nil
end
+
#
# Node to class mapping
#
def class_for(n)
class_mapping = {
@@ -133,19 +153,22 @@
obj.is_a?(Element) ? obj : obj.ordered_elements
end.flatten
end
def all_elements
- @all_elements ||= ordered_elements + (linked_complex_type ? linked_complex_type.ordered_elements : [])
+ @all_elements ||= ordered_elements +
+ (linked_complex_type ? linked_complex_type.all_elements : []) +
+ (referenced_element ? referenced_element.all_elements : [])
end
def child_elements?
elements.length > 0
end
def attributes
- @attributes ||= map_children('xs:attribute')
+ @attributes ||= map_children('xs:attribute') #+
+ #(referenced_element ? referenced_element.attributes : [])
end
def sequences
@sequences ||= map_children("xs:sequence",)
end
@@ -157,10 +180,10 @@
def complex_types
@complex_types ||= map_children("xs:complexType")
end
def complex_type
- complex_types.first || linked_complex_type
+ complex_types.first || linked_complex_type || (referenced_element ? referenced_element.complex_type : nil)
end
def linked_complex_type
@linked_complex_type ||= (schema_for_namespace(type_namespace) || schema).complex_types.find{|ct| ct.name == (type_name || type)}
#@linked_complex_type ||= object_by_name('xs:complexType', type) || object_by_name('xs:complexType', type_name)
\ No newline at end of file