Class: Nylas::Types::UnixTimestampType

Inherits:
ValueType
  • Object
show all
Defined in:
lib/nylas/types.rb

Overview

Type for attributes represented as a unix timestamp in the API and Time in Ruby

Instance Method Summary collapse

Methods inherited from ValueType

#deseralize, #serialize_for_api

Instance Method Details

#cast(object) ⇒ Object

Raises:

  • (TypeError)


85
86
87
88
89
90
91
92
# File 'lib/nylas/types.rb', line 85

def cast(object)
  return object if object.is_a?(Time) || object.nil?
  return Time.at(object.to_i) if object.is_a?(String)
  return Time.at(object) if object.is_a?(Numeric)
  return object.to_time if object.is_a?(Date)

  raise TypeError, "Unable to cast #{object} to Time"
end

#deserialize(object) ⇒ Object



94
95
96
# File 'lib/nylas/types.rb', line 94

def deserialize(object)
  cast(object)
end

#serialize(object) ⇒ Object



98
99
100
101
102
# File 'lib/nylas/types.rb', line 98

def serialize(object)
  return nil if object.nil?

  object.to_i
end