Class: SavonHelper::EnumMapping

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

Overview

EnumMapping maps Savon integers to Ruby symbols.

Converting collapse

Instance Method Summary collapse

Methods inherited from TypeMapping

#description, #object_klass, #warn_unparseable_data

Constructor Details

#initialize(enum, name = '', description = '') ⇒ EnumMapping

A new instance of EnumMapping with description and enum hash enum.

Parameters:

  • enum (Hash{String => Symbol})

    Mapping between Savon Strings and Ruby Symbols.

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


301
302
303
304
# File 'lib/savon_helper/type_mappings.rb', line 301

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

Instance Method Details

#default_valueObject

This method is abstract.

Return the default value the mapping.

Returns:



332
333
334
# File 'lib/savon_helper/type_mappings.rb', line 332

def default_value
  :none
end

#to_native(data, interface) ⇒ Symbol?

Convert from Savon enum-String to Ruby Symbol

Parameters:

  • data (String)

    Source Savon data

Returns:

  • (Symbol, nil)


311
312
313
# File 'lib/savon_helper/type_mappings.rb', line 311

def to_native(data, interface)
  @enum[data]
end

#to_savon(value) ⇒ String

Convert from Ruby DateTime Symbol to Savon enum-String

Parameters:

  • value (Symbol)

    Source Ruby data

Returns:



318
319
320
# File 'lib/savon_helper/type_mappings.rb', line 318

def to_savon(value)
  @enum.key(value)
end

#type_stringString

Return the class description represented by the mapping.

Returns:



326
327
328
# File 'lib/savon_helper/type_mappings.rb', line 326

def type_string
  "enum<#{@enum.values.join(', ')}>"
end