class ActiveAttr::Typecasting::FloatTypecaster

Typecasts an Object to a Float

@example Usage

FloatTypecaster.new.call(1) #=> 1.0

@since 0.5.0

Public Instance Methods

call(value) click to toggle source

Typecasts an object to a Float

Attempts to convert using to_f.

@example Typecast an Integer

typecaster.call(1) #=> 1.0

@param [Object, to_f] value The object to typecast

@return [Float, nil] The result of typecasting

@since 0.5.0

# File lib/active_attr/typecasting/float_typecaster.rb, line 24
def call(value)
  value.to_f if value.present? && value.respond_to?(:to_f)
end