Module: XML::XMLRPC::Parser::ValueParser

Defined in:
lib/xml/libxml/xmlrpc/parser.rb

Overview

Parse values from a XML::Node::Set or Array of XML::Node objects.

May be called recursively by ValueParser::Array or ValueParser::Struct.

Defined Under Namespace

Modules: Array, Struct

Class Method Summary collapse

Class Method Details

.parse(values) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/xml/libxml/xmlrpc/parser.rb', line 190

def self.parse(values)
    parsed_params = []

    values.each do |param_value_node|
        value = nil
        if param_value_node
            param_value_node.each_child do |type|
                value = case type.name.downcase
                        when /^(?:i4|int)$/
                            type.content.strip.to_i
                        when 'string'
                            type.content
                        when 'boolean'
                            if type.content.strip.to_i == 1
                                true
                            else
                                false
                            end
                        when 'double'
                            type.content.strip.to_f
                        when 'datetime.iso8601'
                            # Looks like this: 19980717T14:08:55
                            DateTime.strptime(type.content.strip, "%Y%m%dT%T")
                        when 'base64'
                            Base64.decode64(type.content.strip)
                        when 'struct'
                            Parser::ValueParser::Struct.parse(type)
                        when 'array'
                            Parser::ValueParser::Array.parse(type)
                        end

                break if value
            end
        end
        parsed_params.push value
    end

    return parsed_params
end