Module: Mongoid::Criteria::Queryable::Extensions::Numeric::ClassMethods
- Defined in:
- lib/mongoid/criteria/queryable/extensions/numeric.rb
Instance Method Summary collapse
-
#__numeric__(object) ⇒ Object
private
Get the object as a numeric.
-
#evolve(object) ⇒ Integer
Evolve the object to an integer.
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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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.
72 73 74 75 76 |
# File 'lib/mongoid/criteria/queryable/extensions/numeric.rb', line 72 def evolve(object) __evolve__(object) do |obj| __numeric__(obj) rescue obj end end |