123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/extensions/float.rb

Instance Method Summary

Instance Method Details

#demongoize(object)

Alias for #mongoize.

[ GitHub ]

  
# File 'lib/mongoid/extensions/float.rb', line 46

alias demongoize mongoize

#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.

[ GitHub ]

  
# File 'lib/mongoid/extensions/float.rb', line 37

def mongoize(object)
  return if object.blank?

  if object.is_a?(String)
    object.to_f if object.numeric?
  else
    object.try(:to_f)
  end
end