Class: WSDL::Response::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdl/response/parser.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.

Parses XML responses into Ruby Hash structures with optional schema support.

Defined Under Namespace

Classes: QName

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema: nil, coercer: TypeCoercer) ⇒ Parser

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 Parser.

Parameters:

  • schema (Array<WSDL::XML::Element>, nil) (defaults to: nil)

    optional schema elements

  • coercer (#coerce) (defaults to: TypeCoercer)

    value coercer used for schema simple types



49
50
51
52
# File 'lib/wsdl/response/parser.rb', line 49

def initialize(schema: nil, coercer: TypeCoercer)
  @schema = schema
  @coercer = coercer
end

Instance Attribute Details

#localString (readonly)

Returns:

  • (String)


19
# File 'lib/wsdl/response/parser.rb', line 19

QName = Data.define(:namespace, :local)

#namespaceString? (readonly)

Returns:

  • (String, nil)


19
# File 'lib/wsdl/response/parser.rb', line 19

QName = Data.define(:namespace, :local)

Class Method Details

.parse(xml, schema: nil, unwrap: false) ⇒ Hash, 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.

Parses XML into a nested hash.

Parameters:

  • xml (String, Nokogiri::XML::Document, Nokogiri::XML::Node)
  • schema (Array<WSDL::XML::Element>, nil) (defaults to: nil)

    optional schema for type-aware parsing

  • unwrap (Boolean) (defaults to: false)

    whether to return only the root element value

Returns:

  • (Hash, Object)

    parsed hash, or unwrapped root value when unwrap is true



28
29
30
31
32
33
34
# File 'lib/wsdl/response/parser.rb', line 28

def parse(xml, schema: nil, unwrap: false)
  node = resolve_node(xml)
  return {} unless node

  parsed = new(schema:).convert_node(node)
  unwrap ? parsed.values.first : parsed
end

Instance Method Details

#convert_node(node) ⇒ Hash

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 parsed node.

Parameters:

  • node (Nokogiri::XML::Node)

    node to parse

Returns:

  • (Hash)

    parsed node



56
57
58
59
60
# File 'lib/wsdl/response/parser.rb', line 56

def convert_node(node)
  key = node.name.to_sym
  value = @schema ? convert_with_schema(node, @schema) : convert_without_schema(node)
  { key => value }
end