Method: MiOS.cast

Defined in:
lib/mios/type_conversion.rb

.cast(value, type) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mios/type_conversion.rb', line 5

def self.cast(value, type)
  result = case
  when type == Integer
    value.to_i
  when type == Time
    Time.at(value.to_i)
  when type == Boolean
    value.to_i == 1
  when type == Float
    value.to_f
  else
    value
  end
  result
end