Class: WSDL::Definition::ElementHash Private
- Inherits:
-
Object
- Object
- WSDL::Definition::ElementHash
- Defined in:
- lib/wsdl/definition/element_hash.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Frozen wrapper around a plain element hash that duck-types as XML::Element.
This allows consumers like Response::Parser, Response::Builder, and Request::Validator to work with Definition element data without modification — they call the same methods they would on XML::Element.
Instance Attribute Summary collapse
-
#attributes ⇒ Array<AttributeHash>
readonly
private
Attribute definitions.
-
#children ⇒ Array<ElementHash>
readonly
private
Child elements.
Instance Method Summary collapse
-
#any_content? ⇒ Boolean
private
True if this element allows xs:any wildcard content.
-
#base_type ⇒ String?
private
Base type name (e.g. 'xsd:string').
-
#complex_type? ⇒ Boolean
private
True if this is a complex or recursive type element.
-
#form ⇒ String
private
Element form ('qualified' or 'unqualified').
-
#initialize(data) ⇒ ElementHash
constructor
private
A new instance of ElementHash.
-
#kind ⇒ Symbol
private
Element kind (:simple, :complex, or :recursive).
-
#list? ⇒ Boolean
private
True if this is an xs:list type.
-
#max_occurs ⇒ String
private
MaxOccurs as a string ('unbounded' for infinity).
-
#min_occurs ⇒ String
private
MinOccurs as a string (for Validator compatibility).
-
#name ⇒ String
private
Local element name.
-
#namespace ⇒ String?
private
Namespace URI.
-
#nillable? ⇒ Boolean
private
True if this element can be nil (xsi:nil="true").
-
#optional? ⇒ Boolean
private
True if the element is optional (minOccurs=0).
-
#recursive? ⇒ Boolean
private
True if this element has a recursive type definition.
-
#recursive_type ⇒ String?
private
The recursive type name.
-
#required? ⇒ Boolean
private
True if the element is required (minOccurs>0).
-
#simple_type? ⇒ Boolean
private
True if this is a simple type element.
-
#singular? ⇒ Boolean
private
True if this element appears at most once.
-
#to_a(memo = [], stack = []) ⇒ Array<Array>
private
Converts this element and its children to an Array representation.
-
#to_h ⇒ Hash{Symbol => Object}
private
The underlying element data.
Constructor Details
#initialize(data) ⇒ ElementHash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ElementHash.
15 16 17 18 19 20 |
# File 'lib/wsdl/definition/element_hash.rb', line 15 def initialize(data) @data = data @children = data[:children].map { |c| self.class.new(c) }.freeze @attributes = data[:attributes].map { |a| AttributeHash.new(a) }.freeze freeze end |
Instance Attribute Details
#attributes ⇒ Array<AttributeHash> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns attribute definitions.
111 112 113 |
# File 'lib/wsdl/definition/element_hash.rb', line 111 def attributes @attributes end |
#children ⇒ Array<ElementHash> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns child elements.
108 109 110 |
# File 'lib/wsdl/definition/element_hash.rb', line 108 def children @children end |
Instance Method Details
#any_content? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this element allows xs:any wildcard content.
73 74 75 |
# File 'lib/wsdl/definition/element_hash.rb', line 73 def any_content? @data[:any_content] end |
#base_type ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns base type name (e.g. 'xsd:string').
43 44 45 |
# File 'lib/wsdl/definition/element_hash.rb', line 43 def base_type @data[:xsd_type] end |
#complex_type? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this is a complex or recursive type element.
53 54 55 |
# File 'lib/wsdl/definition/element_hash.rb', line 53 def complex_type? %w[complex recursive].include?(@data[:type]) end |
#form ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns element form ('qualified' or 'unqualified').
33 34 35 |
# File 'lib/wsdl/definition/element_hash.rb', line 33 def form @data[:form] end |
#kind ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns element kind (:simple, :complex, or :recursive).
38 39 40 |
# File 'lib/wsdl/definition/element_hash.rb', line 38 def kind @data[:type].to_sym end |
#list? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this is an xs:list type.
63 64 65 |
# File 'lib/wsdl/definition/element_hash.rb', line 63 def list? @data[:list] end |
#max_occurs ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns maxOccurs as a string ('unbounded' for infinity).
93 94 95 |
# File 'lib/wsdl/definition/element_hash.rb', line 93 def max_occurs @data[:max_occurs] == Float::INFINITY ? 'unbounded' : @data[:max_occurs].to_s end |
#min_occurs ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns minOccurs as a string (for Validator compatibility).
88 89 90 |
# File 'lib/wsdl/definition/element_hash.rb', line 88 def min_occurs @data[:min_occurs].to_s end |
#name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns local element name.
23 24 25 |
# File 'lib/wsdl/definition/element_hash.rb', line 23 def name @data[:name] end |
#namespace ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns namespace URI.
28 29 30 |
# File 'lib/wsdl/definition/element_hash.rb', line 28 def namespace @data[:namespace] end |
#nillable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this element can be nil (xsi:nil="true").
68 69 70 |
# File 'lib/wsdl/definition/element_hash.rb', line 68 def nillable? @data[:nillable] end |
#optional? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the element is optional (minOccurs=0).
98 99 100 |
# File 'lib/wsdl/definition/element_hash.rb', line 98 def optional? @data[:min_occurs].zero? end |
#recursive? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this element has a recursive type definition.
78 79 80 |
# File 'lib/wsdl/definition/element_hash.rb', line 78 def recursive? @data[:type] == 'recursive' end |
#recursive_type ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the recursive type name.
83 84 85 |
# File 'lib/wsdl/definition/element_hash.rb', line 83 def recursive_type @data[:recursive_type] end |
#required? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the element is required (minOccurs>0).
103 104 105 |
# File 'lib/wsdl/definition/element_hash.rb', line 103 def required? !optional? end |
#simple_type? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this is a simple type element.
48 49 50 |
# File 'lib/wsdl/definition/element_hash.rb', line 48 def simple_type? @data[:type] == 'simple' end |
#singular? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this element appears at most once.
58 59 60 |
# File 'lib/wsdl/definition/element_hash.rb', line 58 def singular? @data[:singular] end |
#to_a(memo = [], stack = []) ⇒ Array<Array>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts this element and its children to an Array representation.
Produces the same format as XML::Element#to_a for compatibility with Contract::PartContract#paths.
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity -- mirrors XML::Element#to_a
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/wsdl/definition/element_hash.rb', line 127 def to_a(memo = [], stack = []) new_stack = stack + [name] data = { namespace:, form:, singular: singular?, min_occurs:, max_occurs:, kind: } data[:attributes] = attributes.map(&:to_h) unless attributes.empty? case @data[:type] when 'recursive' then data[:recursive_type] = recursive_type when 'simple' data[:type] = base_type data[:list] = list? when 'complex' then data[:any_content] = any_content? end memo << [new_stack, data] children.each { |child| child.to_a(memo, new_stack) } if @data[:type] == 'complex' memo end |
#to_h ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the underlying element data.
114 115 116 |
# File 'lib/wsdl/definition/element_hash.rb', line 114 def to_h @data end |