Method: ActiveModel::Type::Helpers::Numeric#cast

Defined in:
activemodel/lib/active_model/type/helpers/numeric.rb

#cast(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'activemodel/lib/active_model/type/helpers/numeric.rb', line 15

def cast(value)
  # Checks whether the value is numeric. Spaceship operator
  # will return nil if value is not numeric.
  value = if value <=> 0
    value
  else
    case value
    when true then 1
    when false then 0
    else value.presence
    end
  end

  super(value)
end