8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/daisybill_api/ext/attributes/type_castings.rb', line 8
def convert_to(value, type)
return to_array(value, type.first) if type.is_a? Array
return if value.nil? || (value.is_a?(String) && value.strip.empty?)
return to_class(value, type) if type.is_a? Class
case type
when :integer
to_integer(value)
when :string
to_string(value)
when :date
to_date(value)
when :datetime
to_datetime(value)
when :boolean
to_boolean(value)
when :attachment
to_attachment(value)
when :float
to_float(value)
when :hash
to_hash(value)
else
raise "Unknown Type"
end
end
|