Module: Mongoid::Criteria::Queryable::Extensions::Numeric::ClassMethods

Defined in:
build/mongoid-7.0/lib/mongoid/criteria/queryable/extensions/numeric.rb

Instance Method Summary collapse

Instance Method Details

#__numeric__(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the object as a numeric.

Examples:

Get the object as numeric.

Object.__numeric__("1.442")

Parameters:

  • object (Object)

    The object to convert.

Returns:

  • (Object)

    The converted number.

Since:

  • 1.0.0



60
61
62
# File 'build/mongoid-7.0/lib/mongoid/criteria/queryable/extensions/numeric.rb', line 60

def __numeric__(object)
  object.to_s =~ /(\A[-+]?[0-9]+\z)|(\.0+\z)|(\.\z)/ ? object.to_i : Float(object)
end

#evolve(object) ⇒ Integer

Evolve the object to an integer.

Examples:

Evolve to integers.

Integer.evolve("1")

Parameters:

  • object (Object)

    The object to evolve.

Returns:

  • (Integer)

    The evolved object.

Since:

  • 1.0.0



74
75
76
77
78
# File 'build/mongoid-7.0/lib/mongoid/criteria/queryable/extensions/numeric.rb', line 74

def evolve(object)
  __evolve__(object) do |obj|
    __numeric__(obj) rescue obj
  end
end