Sha256: e68972c68b3a244091b196ba9aa77a9da4315604202ee5b3983cca3334cdf2ff

Contents?: true

Size: 787 Bytes

Versions: 7

Compression:

Stored size: 787 Bytes

Contents

class Array

  # Translates the Array into SOAP compatible XML. See: Hash.to_soap_xml.
  def to_soap_xml(key, attributes = {})
    xml = Builder::XmlMarkup.new

    each_with_index do |item, index|
      attrs = tag_attributes attributes, index
      case item
        when Hash then xml.tag!(key, attrs) { xml << item.to_soap_xml }
        else           xml.tag!(key, attrs) { xml << item.to_soap_value }
      end
    end

    xml.target!
  end

private

  # Takes a Hash of +attributes+ and the +index+ for which to return attributes
  # for duplicate tags.
  def tag_attributes(attributes, index)
    return {} if attributes.empty?

    attributes.inject({}) do |hash, (key, value)|
      value = value[index] if value.kind_of? Array
      hash.merge key => value
    end
  end

end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
johnreitano-savon-0.7.7.5 lib/savon/core_ext/array.rb
johnreitano-savon-0.7.7.4 lib/savon/core_ext/array.rb
johnreitano-savon-0.7.7.3 lib/savon/core_ext/array.rb
johnreitano-savon-0.7.7.2 lib/savon/core_ext/array.rb
johnreitano-savon-0.7.7.1 lib/savon/core_ext/array.rb
hoopla-savon-0.7.6 lib/savon/core_ext/array.rb
savon-0.7.6 lib/savon/core_ext/array.rb