module Valideizer::Caster
Public Instance Methods
cast_from_json(value)
click to toggle source
# File lib/valideizer/caster.rb, line 5 def cast_from_json(value) JSON.parse(value) rescue nil end
cast_to_boolean(value)
click to toggle source
# File lib/valideizer/caster.rb, line 25 def cast_to_boolean(value) if %w(1 true).include?(value.to_s.downcase) true elsif %w(0 false).include?(value.to_s.downcase) false end end
cast_to_float(value)
click to toggle source
# File lib/valideizer/caster.rb, line 13 def cast_to_float(value) value.to_f rescue nil end
cast_to_integer(value)
click to toggle source
# File lib/valideizer/caster.rb, line 9 def cast_to_integer(value) value.to_i rescue nil end
cast_to_time(value)
click to toggle source
# File lib/valideizer/caster.rb, line 17 def cast_to_time(value) DateTime.parse(value) rescue nil end
cast_to_time_with_format(value, format)
click to toggle source
# File lib/valideizer/caster.rb, line 21 def cast_to_time_with_format(value, format) DateTime.strptime(value, format) rescue nil end