Class: XsdReader::Element
- Inherits:
-
Object
- Object
- XsdReader::Element
show all
- Includes:
- Shared
- Defined in:
- lib/xsd_reader/element.rb
Instance Attribute Summary
Attributes included from Shared
#options
Instance Method Summary
collapse
Methods included from Shared
#[], #all_elements, #base, #base_name, #base_namespace, #child_elements?, #choices, #class_for, #complex_content, #complex_contents, #complex_types, #direct_elements, #extension, #extensions, #initialize, #linked_complex_type, #linked_simple_type, #logger, #map_children, #mappable_children, #name, #node, #node_to_object, #nodes, #object_by_name, #ordered_elements, #parent, #schema, #schema_for_namespace, #sequences, #simple_content, #simple_contents, #simple_types, #type, #type_name, #type_namespace
Instance Method Details
#attributes ⇒ Object
12
13
14
|
# File 'lib/xsd_reader/element.rb', line 12
def attributes
@_element_attributes ||= super + (complex_type ? complex_type.attributes : [])
end
|
#complex_type ⇒ Object
16
17
18
|
# File 'lib/xsd_reader/element.rb', line 16
def complex_type
@_element_complex_type ||= super || linked_complex_type
end
|
#elements(opts = {}) ⇒ Object
7
8
9
10
|
# File 'lib/xsd_reader/element.rb', line 7
def elements(opts = {})
return super if opts[:direct] == true
all_elements
end
|
#family_tree(stack = []) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/xsd_reader/element.rb', line 42
def family_tree(stack = [])
logger.warn('Usage of the family tree function is not recommended as it can take very long to execute and is very memory intensive')
return @_cached_family_tree if @_cached_family_tree
if stack.include?(name)
return nil
end
return "type:#{type_name}" if elements.length == 0
result = elements.inject({}) do |tree, element|
tree.merge element.name => element.family_tree(stack + [name])
end
@_cached_family_tree = result if stack == []
return result
end
|
#max_occurs ⇒ Object
24
25
26
27
28
|
# File 'lib/xsd_reader/element.rb', line 24
def max_occurs
if val = node.attributes['maxOccurs'] ? node.attributes['maxOccurs'].value : nil
val == 'unbounded' ? :unbounded : val.to_i
end
end
|
#min_occurs ⇒ Object
20
21
22
|
# File 'lib/xsd_reader/element.rb', line 20
def min_occurs
node.attributes['minOccurs'] ? node.attributes['minOccurs'].value.to_i : nil
end
|
#multiple_allowed? ⇒ Boolean
30
31
32
|
# File 'lib/xsd_reader/element.rb', line 30
def multiple_allowed?
max_occurs == :unbounded || max_occurs.to_i > 0
end
|
#optional? ⇒ Boolean
38
39
40
|
# File 'lib/xsd_reader/element.rb', line 38
def optional?
!required?
end
|
#required? ⇒ Boolean
34
35
36
|
# File 'lib/xsd_reader/element.rb', line 34
def required?
min_occurs.nil? || min_occurs.to_i > 0
end
|