AWS services or capabilities described in AWS Documentation may vary by region/location. Click
Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Class: Aws::Record::Marshalers::DateMarshaler
- Inherits:
-
Object
- Object
- Aws::Record::Marshalers::DateMarshaler
show all
- Defined in:
- lib/aws-record/record/marshalers/date_marshaler.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DateMarshaler.
21
22
23
|
# File 'lib/aws-record/record/marshalers/date_marshaler.rb', line 21
def initialize(opts = {})
@formatter = opts[:formatter] || Iso8601Formatter
end
|
Instance Method Details
#serialize(raw_value) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/aws-record/record/marshalers/date_marshaler.rb', line 40
def serialize(raw_value)
date = type_cast(raw_value)
if date.nil?
nil
elsif date.is_a?(Date)
@formatter.format(date)
else
raise ArgumentError, "expected a Date value or nil, got #{date.class}"
end
end
|
#type_cast(raw_value) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/aws-record/record/marshalers/date_marshaler.rb', line 25
def type_cast(raw_value)
case raw_value
when nil
nil
when ''
nil
when Date
raw_value
when Integer
Date.parse(Time.at(raw_value).to_s) else
Date.parse(raw_value.to_s) end
end
|