Class: Hash
Instance Method Summary collapse
-
#find_regexp(regexp) ⇒ Object
Expects an Array of Regexp Objects of which every Regexp recursively matches a key to be accessed.
-
#map_soap_response ⇒ Object
Maps keys and values of a Hash created from SOAP response XML to more convenient Ruby Objects.
-
#to_soap_xml ⇒ Object
Returns the Hash translated into SOAP request compatible XML.
Instance Method Details
#find_regexp(regexp) ⇒ Object
Expects an Array of Regexp Objects of which every Regexp recursively matches a key to be accessed. Returns the value of the last Regexp filter found in the Hash or an empty Hash in case the path of Regexp filters did not match the Hash structure.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/savon/core_ext/hash.rb', line 7 def find_regexp(regexp) regexp = [regexp] unless regexp.kind_of? Array result = dup regexp.each do |pattern| result_key = result.keys.find { |key| key.to_s.match pattern } result = result[result_key] ? result[result_key] : {} end result end |
#map_soap_response ⇒ Object
Maps keys and values of a Hash created from SOAP response XML to more convenient Ruby Objects.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/savon/core_ext/hash.rb', line 32 def map_soap_response inject({}) do |hash, (key, value)| key = key.strip_namespace.snakecase.to_sym value = case value when Hash value["xsi:nil"] ? nil : value.map_soap_response when Array value.map { |a_value| a_value.map_soap_response rescue a_value } when String value.map_soap_response end hash.merge key => value end end |
#to_soap_xml ⇒ Object
Returns the Hash translated into SOAP request compatible XML.
Example
{ :find_user => { :id => 666 } }.to_soap_xml
=> "<findUser><id>666</id></findUser>"
24 25 26 27 28 |
# File 'lib/savon/core_ext/hash.rb', line 24 def to_soap_xml @soap_xml = Builder::XmlMarkup.new each { |key, value| nested_data_to_soap_xml key, value } @soap_xml.target! end |