Class: Aws::Record::Marshalers::EpochTimeMarshaler

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-record/record/marshalers/epoch_time_marshaler.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ EpochTimeMarshaler

Returns a new instance of EpochTimeMarshaler.



9
10
11
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 9

def initialize(opts = {})
  @use_local_time = opts[:use_local_time] ? true : false
end

Instance Method Details

#serialize(raw_value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 22

def serialize(raw_value)
  time = type_cast(raw_value)
  if time.nil?
    nil
  elsif time.is_a?(::Time)
    time.to_i
  else
    msg = "expected a Time value or nil, got #{time.class}"
    raise ArgumentError, msg
  end
end

#type_cast(raw_value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 13

def type_cast(raw_value)
  value = _format(raw_value)
  if !@use_local_time && value.is_a?(::Time)
    value.utc
  else
    value
  end
end