123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::Integer::ClassMethods

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

Instance Method Summary

Instance Method Details

#demongoize(object)

Alias for #mongoize.

[ GitHub ]

  
# File 'lib/mongoid/extensions/integer.rb', line 61

alias :demongoize :mongoize

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

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

Examples:

Mongoize the object.

BigDecimal.mongoize("123.11")

Returns:

  • (Integer | nil)

    The object mongoized or nil.

[ GitHub ]

  
# File 'lib/mongoid/extensions/integer.rb', line 51

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