Class: SavonHelper::TypeMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/savon_helper/type_mappings.rb

Overview

A TypeMapping class is responsible for converting between Savon primitive types and Ruby Types

Converting collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = '', description = '') ⇒ TypeMapping

A new instance of TypeMapping with description

Parameters:

  • description (String) (defaults to: '')

    A String describing the mapping.



11
12
13
14
# File 'lib/savon_helper/type_mappings.rb', line 11

def initialize(name='', description='')
  @name = name
  @description = description
end

Instance Method Details

#default_valueObject

This method is abstract.

Return the default value the mapping.

Returns:



54
55
56
# File 'lib/savon_helper/type_mappings.rb', line 54

def default_value
  raise "#{self.class}##{__method__}() not implemented!"
end

#descriptionString

Return the description

Returns:



36
37
38
# File 'lib/savon_helper/type_mappings.rb', line 36

def description
  @description
end

#object_klassClass

This method is abstract.

Return the class represented by the mapping.

Returns:

  • (Class)


42
43
44
# File 'lib/savon_helper/type_mappings.rb', line 42

def object_klass
  raise "#{self.class}##{__method__}() not implemented!"
end

#to_native(data) ⇒ Object

This method is abstract.

Convert from Savon data to Ruby value

Parameters:

  • data (Hash, Object)

    Source Savon data

Returns:



21
22
23
# File 'lib/savon_helper/type_mappings.rb', line 21

def to_native(data)
  raise "#{self.class}##{__method__}(#{data.inspect}) not implemented!"
end

#to_savon(value) ⇒ Object

This method is abstract.

Convert from Ruby value type to Savon data

Parameters:

  • value (Object)

    Source Ruby value

Returns:



28
29
30
# File 'lib/savon_helper/type_mappings.rb', line 28

def to_savon(value)
  raise "#{self.class}##{__method__}(#{value.inspect}) not implemented!"
end

#type_stringString

This method is abstract.

Return the class description represented by the mapping.

Returns:



48
49
50
# File 'lib/savon_helper/type_mappings.rb', line 48

def type_string
  raise "#{self.class}##{__method__}() not implemented!"
end

#warn_unparseable_data(data, interface) ⇒ Object

TODO:

Check if mappings can be derived from klass

Warn about unparsable mapping

Parameters:

  • data (Hash, Object)

    Source Savon data



61
62
63
64
65
# File 'lib/savon_helper/type_mappings.rb', line 61

def warn_unparseable_data(data, interface)
  message = "Can't parse #{type_string} #{@name.inspect}: #{data.inspect}"
  interface.logger.warn(message)
  self.default_value()
end