Class: Soap::Parser::Types
- Inherits:
-
Object
- Object
- Soap::Parser::Types
- Defined in:
- lib/soap/parser/types.rb
Constant Summary collapse
- VALIDATION_ATTRIBUTES =
%i[nillable default minOccurs maxOccurs].freeze
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(namespaces, node) ⇒ Types
constructor
A new instance of Types.
- #parse ⇒ Object
-
#parse_type(node, name) ⇒ Object
rubocop:disable all.
- #parse_types ⇒ Object
- #simple_type ⇒ Object
Constructor Details
#initialize(namespaces, node) ⇒ Types
Returns a new instance of Types.
13 14 15 16 17 |
# File 'lib/soap/parser/types.rb', line 13 def initialize(namespaces, node) @namespaces = namespaces @node = node @hash = {} end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
9 10 11 |
# File 'lib/soap/parser/types.rb', line 9 def hash @hash end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
11 12 13 |
# File 'lib/soap/parser/types.rb', line 11 def namespaces @namespaces end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
10 11 12 |
# File 'lib/soap/parser/types.rb', line 10 def node @node end |
Instance Method Details
#parse ⇒ Object
19 20 21 |
# File 'lib/soap/parser/types.rb', line 19 def parse parse_types end |
#parse_type(node, name) ⇒ Object
rubocop:disable all
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/soap/parser/types.rb', line 51 def parse_type(node, name) element = {} element[name] ||= { params: [] } node.xpath("./xsd:complexContent/xsd:extension/xsd:sequence/xsd:element").each do |inner| elem_name = inner.attribute("name").to_s elem_type = inner.attribute("type").to_s elem_attributes = VALIDATION_ATTRIBUTES.each.with_object({}) do |attr, attrs| value = inner.attribute(attr.to_s) attrs[attr] = value.to_s if value end element[name][:params] << { name: elem_name, type: elem_type, attributes: elem_attributes } end node.xpath("./xsd:sequence/xsd:element").each do |inner| elem_name = inner.attribute("name").value elem_type = inner.attribute("type").value elem_attributes = VALIDATION_ATTRIBUTES.each.with_object({}) do |attr, attrs| value = inner.attribute(attr.to_s) attrs[attr] = value.to_s if value end element[name][:params] << { name: elem_name, type: elem_type, attributes: elem_attributes } end element end |
#parse_types ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/soap/parser/types.rb', line 23 def parse_types schemas.each do |schema| namespace = @namespaces.key(schema["targetNamespace"]) @hash[namespace] = {} schema.element_children.each do |node| case node.name when "element" if !node.children.empty? node_type = node.at_xpath("./xsd:complexType") else complex_type = node.attribute("type").to_s node_type = schema.at_xpath( "xsd:complexType[@name='#{complex_type.split(':').last}']" ) end @hash[namespace].merge!(parse_type(node_type, node["name"])) when "complexType" @hash[namespace].merge!(parse_type(node, node["name"])) end end end end |
#simple_type ⇒ Object
46 47 48 |
# File 'lib/soap/parser/types.rb', line 46 def simple_type { "base" => @node.at_xpath("./xs|xsd:restriction")["base"] } end |