Module: XsdModel::Elements::BaseElement
- Extended by:
- AttributeMethods
- Included in:
- All, Annotation, Any, AnyAttribute, Appinfo, Attribute, AttributeGroup, Choice, Collection, Comment, ComplexContent, ComplexType, Content, Doctype, Document, Documentation, Element, Enumeration, Extension, FractionDigits, Group, Import, Include, Length, Logical, MaxInclusive, MaxLength, MinExclusive, MinInclusive, MinLength, Pattern, Restriction, Schema, SchemaInfo, Sequence, SimpleContent, SimpleType, Text, TotalDigits, Union, WhiteSpace
- Defined in:
- lib/xsd_model/elements/base_element.rb
Constant Summary
collapse
- XSD_URI =
'http://www.w3.org/2001/XMLSchema'
Instance Attribute Summary collapse
Instance Method Summary
collapse
attribute_method
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
TODO: add similar #respond_to? method
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/xsd_model/elements/base_element.rb', line 57
def method_missing(name, *args)
super if name.to_s.end_with? '?'
if XsdModel::Elements.const_defined? name.camelize
const = XsdModel::Elements.const_get name.camelize
children.select { |child| child.is_a? const }
elsif XsdModel::Elements.const_defined? name.camelize.singularize
const = XsdModel::Elements.const_get name.camelize.singularize
children.select { |child| child.is_a? const }
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
12
13
14
|
# File 'lib/xsd_model/elements/base_element.rb', line 12
def attributes
@attributes
end
|
#children ⇒ Object
Returns the value of attribute children.
12
13
14
|
# File 'lib/xsd_model/elements/base_element.rb', line 12
def children
@children
end
|
#namespaces ⇒ Object
Returns the value of attribute namespaces.
12
13
14
|
# File 'lib/xsd_model/elements/base_element.rb', line 12
def namespaces
@namespaces
end
|
Instance Method Details
#==(other) ⇒ Object
43
44
45
46
|
# File 'lib/xsd_model/elements/base_element.rb', line 43
def ==(other)
(attributes == other.attributes) &&
(children == other.children)
end
|
#basic_xsd_type? ⇒ Boolean
35
36
37
|
# File 'lib/xsd_model/elements/base_element.rb', line 35
def basic_xsd_type?
has_type? && type.start_with?("#{xsd_prefix}:")
end
|
#element_name ⇒ Object
27
28
29
|
# File 'lib/xsd_model/elements/base_element.rb', line 27
def element_name
self.class.name.demodulize.underscore
end
|
#empty? ⇒ Boolean
39
40
41
|
# File 'lib/xsd_model/elements/base_element.rb', line 39
def empty?
children.empty?
end
|
#has_custom_type? ⇒ Boolean
31
32
33
|
# File 'lib/xsd_model/elements/base_element.rb', line 31
def has_custom_type?
has_type? && !type.start_with?("#{xsd_prefix}:")
end
|
#initialize(*args) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/xsd_model/elements/base_element.rb', line 15
def initialize(*args)
hashes, rest = args.partition { |arg| arg.is_a? Hash }
@children = rest.flatten
@attributes = hashes[0] || {}
@namespaces = hashes[1] || {}
end
|
#reverse_traverse {|_self, children_result| ... } ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/xsd_model/elements/base_element.rb', line 48
def reverse_traverse(&block)
children_result = children.map do |child|
child.reverse_traverse(&block)
end
yield self, children_result
end
|
#xsd_prefix ⇒ Object
23
24
25
|
# File 'lib/xsd_model/elements/base_element.rb', line 23
def xsd_prefix
namespaces.invert[XSD_URI].gsub('xmlns:', '')
end
|