Method: FulfilApi::Resource::AttributeType#cast_value

Defined in:
lib/fulfil_api/resource/attribute_type.rb

#cast_valueAny

Casts the attribute value to an useable format for a Ruby application.

Returns:

  • (Any)


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fulfil_api/resource/attribute_type.rb', line 35

def cast_value
  case @type
  when "bytes" then Base64.decode64(value_before_cast)
  when "date" then Date.parse(value_before_cast)
  when "datetime" then DateTime.parse(value_before_cast)
  when "decimal" then BigDecimal(value_before_cast)
  when "time" then Time.parse(value_before_cast)
  when "timedelta" then value_before_cast
  else
    @value
  end
end