Class: SavonHelper::ArrayMapping
- Inherits:
-
TypeMapping
- Object
- TypeMapping
- SavonHelper::ArrayMapping
- Defined in:
- lib/savon_helper/type_mappings.rb
Overview
ArrayMapping maps Savon data to Ruby Arrays
Instance Attribute Summary
Attributes inherited from TypeMapping
Converting collapse
-
#to_native(data, interface) ⇒ Array<@element_mapping>
Convert from Savon data to Ruby value.
Class Method Summary collapse
-
.to_native(element_mapping, data, interface, array_mapping = nil) ⇒ Array<element_mapping>
Convert the given Savon data to an Array consisting of elements described by element_mapping.
Instance Method Summary collapse
- #default_value ⇒ Object abstract
-
#initialize(element_mapping, name = '', description = '') ⇒ ArrayMapping
constructor
A new instance of TypeMapping with description.
-
#object_klass ⇒ Class
Return the class represented by the mapping.
-
#type_string ⇒ String
Return the class description represented by the mapping.
Methods inherited from TypeMapping
Constructor Details
#initialize(element_mapping, name = '', description = '') ⇒ ArrayMapping
A new instance of TypeMapping with description
419 420 421 422 |
# File 'lib/savon_helper/type_mappings.rb', line 419 def initialize(element_mapping, name='', description='') super(name, description) @element_mapping = element_mapping end |
Class Method Details
.to_native(element_mapping, data, interface, array_mapping = nil) ⇒ Array<element_mapping>
Convert the given Savon data to an Array consisting of elements described by element_mapping
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/savon_helper/type_mappings.rb', line 392 def self.to_native(element_mapping, data, interface, array_mapping = nil) result = [] return result if data.blank? if data.is_a?(Array) data.each do |element| result << element_mapping.to_native(element, interface) end elsif data.is_a?(Hash) item = data[:item] if item.nil? result << element_mapping.to_native(data, interface) else result = to_native(element_mapping, item, interface, array_mapping) end else = "Can't parse" = + " #{array_mapping.type_string} #{array_mapping.name.inspect}" if array_mapping = + ": #{data.inspect}" interface.logger.warn() end result end |
Instance Method Details
#default_value ⇒ Object
This method is abstract.
Return the default value the mapping.
449 450 451 |
# File 'lib/savon_helper/type_mappings.rb', line 449 def default_value [] end |
#object_klass ⇒ Class
Return the class represented by the mapping.
437 438 439 |
# File 'lib/savon_helper/type_mappings.rb', line 437 def object_klass @element_mapping.object_klass end |
#to_native(data, interface) ⇒ Array<@element_mapping>
Convert from Savon data to Ruby value
429 430 431 |
# File 'lib/savon_helper/type_mappings.rb', line 429 def to_native(data, interface) return self.class.to_native(@element_mapping, data, interface, self) end |
#type_string ⇒ String
Return the class description represented by the mapping.
443 444 445 |
# File 'lib/savon_helper/type_mappings.rb', line 443 def type_string "Array<#{@element_mapping.type_string}>" end |