Class: Savon::QualifiedMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/qualified_message.rb

Instance Method Summary collapse

Constructor Details

#initialize(types, used_namespaces, key_converter) ⇒ QualifiedMessage

Returns a new instance of QualifiedMessage.



6
7
8
9
10
# File 'lib/savon/qualified_message.rb', line 6

def initialize(types, used_namespaces, key_converter)
  @types           = types
  @used_namespaces = used_namespaces
  @key_converter   = key_converter
end

Instance Method Details

#to_hash(hash, path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/savon/qualified_message.rb', line 12

def to_hash(hash, path)
  return hash unless hash
  return hash.map { |value| to_hash(value, path) } if hash.is_a?(Array)
  return hash.to_s unless hash.is_a?(Hash)

  hash.each_with_object({}) do |(key, value), newhash|
    case key
    when :order!
      newhash[key] = add_namespaces_to_values(value, path)
    when :attributes!, :content!
      newhash[key] = to_hash(value, path)
    else
      if key.to_s =~ /!$/
        newhash[key] = value
      else
        translated_key  = translate_tag(key)
        newkey          = add_namespaces_to_values(key, path).first
        newpath         = path + [translated_key]
        newhash[newkey] = to_hash(value, @types[newpath] ? [@types[newpath]] : newpath)
      end
    end
    newhash
  end
end