Class: SavonHelper::DatetimeMapping

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

Overview

DatetimeMapping maps Savon data to Ruby DateTimes.

Instance Attribute Summary

Attributes inherited from TypeMapping

#description, #name

Converting collapse

Instance Method Summary collapse

Methods inherited from TypeMapping

#initialize

Constructor Details

This class inherits a constructor from SavonHelper::TypeMapping

Instance Method Details

#default_valueObject

This method is abstract.

Return the default value the mapping.

Returns:



275
276
277
# File 'lib/savon_helper/type_mappings.rb', line 275

def default_value
  DateTime.now()
end

#object_klassDateTime

Return the class represented by the mapping.

Returns:

  • (DateTime)


263
264
265
# File 'lib/savon_helper/type_mappings.rb', line 263

def object_klass
  DateTime
end

#to_native(data, interface) ⇒ DateTime

Convert from Savon data to Ruby datetime

Parameters:

  • data (Hash, String)

    Source Savon data

Returns:

  • (DateTime)


248
249
250
# File 'lib/savon_helper/type_mappings.rb', line 248

def to_native(data, interface)
  DateTime.parse(data.to_s)
end

#to_savon(value) ⇒ String

Convert from Ruby DateTime type to Savon data

Parameters:

  • value (DateTime)

    Source Ruby data

Returns:



255
256
257
# File 'lib/savon_helper/type_mappings.rb', line 255

def to_savon(value)
  value.to_datetime.to_s
end

#type_stringString

Return the class description represented by the mapping.

Returns:



269
270
271
# File 'lib/savon_helper/type_mappings.rb', line 269

def type_string
  "datetime"
end