Module: Mongoid::Criteria::Queryable::Extensions::Numeric::ClassMethods
Relationships & Source Files | |
Defined in: | lib/mongoid/criteria/queryable/extensions/numeric.rb |
Instance Method Summary
-
#__numeric__(object) ⇒ Object
Internal use only
Internal use only
Get the object as a numeric.
-
#evolve(object) ⇒ Integer
Evolve the object to an integer.
Instance Method Details
#__numeric__(object) ⇒ Object
This method is for internal use only.
Get the object as a numeric.
# File 'lib/mongoid/criteria/queryable/extensions/numeric.rb', line 46
def __numeric__(object) str = object.to_s raise ArgumentError if str.empty? # These requirements seem a bit odd, but they're explicitly specified in the tests, # so we're obligated to keep them, for now. (This code was rewritten from a one-line # regex, due to security concerns with a polynomial regex being used on uncontrolled # data). str = str.chop if str.end_with?('.') return 0 if str.empty? result = Integer(str) rescue Float(object) integer = result.to_i integer == result ? integer : result end
#evolve(object) ⇒ Integer
Evolve the object to an integer.
# File 'lib/mongoid/criteria/queryable/extensions/numeric.rb', line 72
def evolve(object) __evolve__(object) do |obj| __numeric__(obj) rescue obj end end