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

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

Instance Method Summary collapse

Instance Method Details

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



46
47
48
49
50
51
52
53
54
55
# File 'build/mongoid-master/lib/mongoid/extensions/integer.rb', line 46

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