Class: SavonHelper::DatetimeMapping

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

Overview

DatetimeMapping maps Savon data to Ruby DateTimes.

Converting collapse

Instance Method Summary collapse

Methods inherited from TypeMapping

#description, #initialize, #warn_unparseable_data

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:



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

def default_value
  DateTime.now()
end

#object_klassDateTime

Return the class represented by the mapping.

Returns:

  • (DateTime)


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

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)


261
262
263
# File 'lib/savon_helper/type_mappings.rb', line 261

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:



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

def to_savon(value)
  value.to_datetime.to_s
end

#type_stringString

Return the class description represented by the mapping.

Returns:



282
283
284
# File 'lib/savon_helper/type_mappings.rb', line 282

def type_string
  "datetime"
end