Class: Aws::Record::Marshalers::FloatMarshaler

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FloatMarshaler

Returns a new instance of FloatMarshaler.



8
9
# File 'lib/aws-record/record/marshalers/float_marshaler.rb', line 8

def initialize(opts = {})
end

Instance Method Details

#serialize(raw_value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws-record/record/marshalers/float_marshaler.rb', line 26

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

#type_cast(raw_value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/aws-record/record/marshalers/float_marshaler.rb', line 11

def type_cast(raw_value)
  case raw_value
  when nil
    nil
  when ''
    nil
  when Float
    raw_value
  else
    raw_value.respond_to?(:to_f) ?
      raw_value.to_f :
      raw_value.to_s.to_f
  end
end