Class: WSDL::Response::TypeCoercer Private
- Inherits:
-
Object
- Object
- WSDL::Response::TypeCoercer
- Includes:
- Log
- Defined in:
- lib/wsdl/response/type_coercer.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.
Coerces XML text values into Ruby values based on XSD types.
Constant Summary collapse
- STRING_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
XSD simple types mapped to string coercion.
Includes primitive string types, Gregorian date fragments (which can have timezone suffixes that would be lost if converted), duration (no stdlib Ruby type), and meta-types (anyType, anySimpleType).
%w[ string normalizedString token language Name NCName ID IDREF ENTITY NMTOKEN anyURI QName duration gYear gYearMonth gMonthDay gDay gMonth NOTATION anyType anySimpleType ].freeze
- LIST_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
XSD list types mapped to whitespace-split coercion.
Per XSD Part 2 §3.3.1, these are lists of the singular form (IDREF, ENTITY, NMTOKEN) separated by whitespace.
%w[IDREFS ENTITIES NMTOKENS].freeze
- INTEGER_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
XSD simple types mapped to integer coercion.
%w[ integer int long short byte nonNegativeInteger positiveInteger nonPositiveInteger negativeInteger unsignedLong unsignedInt unsignedShort unsignedByte ].freeze
- TYPE_GROUPS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps XSD local type names to coercion groups.
begin groups = {} STRING_TYPES.each do |type| groups[type] = :string end LIST_TYPES.each do |type| groups[type] = :list end INTEGER_TYPES.each do |type| groups[type] = :integer end groups['decimal'] = :decimal groups['float'] = :float groups['double'] = :float groups['boolean'] = :boolean groups['date'] = :date groups['dateTime'] = :datetime groups['time'] = :time groups['base64Binary'] = :base64 groups['hexBinary'] = :hex_binary groups.freeze end
- GROUP_HANDLERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Group-to-handler map used by coerce.
{ string: ->(value) { convert_string(value) }, integer: ->(value) { convert_integer(value) }, decimal: ->(value) { convert_decimal(value) }, float: ->(value) { convert_float(value) }, boolean: ->(value) { convert_boolean(value) }, date: ->(value) { convert_date(value) }, datetime: ->(value) { convert_datetime(value) }, time: ->(value) { convert_time(value) }, base64: ->(value) { convert_base64(value) }, hex_binary: ->(value) { convert_hex_binary(value) }, list: ->(value) { convert_list(value) } }.freeze
- FLOAT_SPECIAL_VALUES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
XSD float/double special value lexical representations.
Per XSD Part 2 §3.2.4.1 and §3.2.5.1, these are
INF,-INF, andNaN. { 'INF' => Float::INFINITY, '-INF' => -Float::INFINITY, 'NaN' => Float::NAN }.freeze
- TIMEZONE_SUFFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches ISO8601 timezone suffixes accepted for XSD dateTime/time parsing.
/(Z|[+-](?:0[0-9]|1[0-3]):[0-5][0-9]|[+-]14:00)\z/
Class Method Summary collapse
-
.coerce(value, type) ⇒ Object
private
Coerces a text value based on its XSD type.
Methods included from Log
Class Method Details
.coerce(value, type) ⇒ 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.
Coerces a text value based on its XSD type.
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/wsdl/response/type_coercer.rb', line 110 def coerce(value, type) return value if value.nil? || value.empty? local_type = type&.split(':')&.last group = TYPE_GROUPS[local_type] handler = GROUP_HANDLERS[group] return value unless handler handler.call(value) end |