Class: SavonHelper::EnumMapping

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

Overview

EnumMapping maps Savon integers to Ruby symbols.

Instance Attribute Summary

Attributes inherited from TypeMapping

#description, #name

Converting collapse

Instance Method Summary collapse

Methods inherited from TypeMapping

#object_klass

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: '')


288
289
290
291
# File 'lib/savon_helper/type_mappings.rb', line 288

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:



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

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)


298
299
300
# File 'lib/savon_helper/type_mappings.rb', line 298

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:



305
306
307
# File 'lib/savon_helper/type_mappings.rb', line 305

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

#type_stringString

Return the class description represented by the mapping.

Returns:



313
314
315
# File 'lib/savon_helper/type_mappings.rb', line 313

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