Class: IronAdmin::Import::TypeCaster

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_admin/import/type_caster.rb

Instance Method Summary collapse

Instance Method Details

#cast(value, field) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/iron_admin/import/type_caster.rb', line 9

def cast(value, field)
  return nil if blank_value?(value)

  case field.type
  when :boolean then cast_boolean(value)
  when :integer then Integer(value)
  when :float then Float(value)
  when :decimal then BigDecimal(value.to_s)
  when :number then cast_number(value)
  when :json then cast_json(value)
  when :date then Date.parse(value.to_s)
  when :datetime then Time.zone.parse(value.to_s)
  else value
  end
end