Module: Mongoid::Extensions::Float::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/extensions/float.rb

Instance Method Summary collapse

Instance Method Details

#mongoize(object) ⇒ Float | nil Also known as: demongoize

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Float.mongoize("123.11")

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Float | nil)

    The object mongoized or nil.



38
39
40
41
42
43
44
45
46
47
# File 'build/mongoid-master/lib/mongoid/extensions/float.rb', line 38

def mongoize(object)
  return if object.blank?
  if object.is_a?(String)
    if object.numeric?
      object.to_f
    end
  else
    object.try(:to_f)
  end
end