Class: MyData::Xsd::Element
- Inherits:
-
Object
- Object
- MyData::Xsd::Element
- Defined in:
- lib/my_data/xsd/element.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #collection? ⇒ Boolean
- #collection_element_name ⇒ Object
-
#initialize(element, namespace: nil, force_collection: nil) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
- #name ⇒ Object
- #required? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(element, namespace: nil, force_collection: nil) ⇒ Element
Returns a new instance of Element.
6 7 8 9 10 |
# File 'lib/my_data/xsd/element.rb', line 6 def initialize(element, namespace: nil, force_collection: nil) @element = element @namespace = namespace force_collection && @collection = force_collection end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
4 5 6 |
# File 'lib/my_data/xsd/element.rb', line 4 def element @element end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/my_data/xsd/element.rb', line 4 def namespace @namespace end |
Instance Method Details
#collection? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/my_data/xsd/element.rb', line 28 def collection? return @collection if defined? @collection @collection = element.to_s.include? "maxOccurs" end |
#collection_element_name ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/my_data/xsd/element.rb', line 34 def collection_element_name return @collection_element_name if defined? @collection_element_name @collection_element_name = if collection? nested_element = element.at_xpath(".//xs:element") nested_element ? nested_element.attributes["name"].value : nil end end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/my_data/xsd/element.rb', line 48 def inspect "Element: { name: #{name.to_json}, type: #{type.to_json}, collection: #{collection?} }" end |
#name ⇒ Object
12 13 14 |
# File 'lib/my_data/xsd/element.rb', line 12 def name @name ||= element.attributes["name"].value end |
#required? ⇒ Boolean
44 45 46 |
# File 'lib/my_data/xsd/element.rb', line 44 def required? element.attributes["minOccurs"]&.value != "0" end |
#type ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/my_data/xsd/element.rb', line 16 def type @type = begin extracted_type = element.attributes["type"] || element.at_xpath(".//xs:element[@type]")&.attributes.try(:[], "type") || element.at_xpath(".//xs:restriction[@base]")&.attributes.try(:[], "base") camelize_type(extracted_type.value) end end |