Method: Bj::Table::Config::ClassMethods#cast_for

Defined in:
lib/bj/table.rb

#cast_for(value) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/bj/table.rb', line 318

def cast_for value
  case value
    when TrueClass, FalseClass
      'to_bool'
    when NilClass
      'to_nil'
    when Fixnum, Bignum
      'to_i'
    when Float
      'to_f'
    when Time
      'to_time'
    when Symbol
      'to_sym'
    else
      case value.to_s
        when %r/^\d+$/
          'to_i'
        when %r/^\d+\.\d+$/
          'to_f'
        when %r/^nil$|^$/
          'to_nil'
        when %r/^true|false$/
          'to_bool'
        else
          'to_s'
      end
  end
end