Sha256: 34a315d1c47767fdf9501a2af9315b3fe39b3f1075f3af9285c6492145fce967

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

# encoding: utf-8
module Mongoid
  module Extensions
    module Float

      # Convert the float into a time.
      #
      # @example Convert the float into a time.
      #   1335532685.117847.__mongoize_time__
      #
      # @return [ Time ] The float as a time.
      #
      # @since 3.0.0
      def __mongoize_time__
        ::Time.at(self)
      end

      # Is the float a number?
      #
      # @example Is the object a number?.
      #   object.numeric?
      #
      # @return [ true ] Always true.
      #
      # @since 3.0.0
      def numeric?
        true
      end

      module ClassMethods

        # Turn the object from the ruby type we deal with to a Mongo friendly
        # type.
        #
        # @example Mongoize the object.
        #   Float.mongoize("123.11")
        #
        # @param [ Object ] object The object to mongoize.
        #
        # @return [ String ] The object mongoized.
        #
        # @since 3.0.0
        def mongoize(object)
          unless object.blank?
            __numeric__(object) rescue 0.0
          else
            nil
          end
        end
      end
    end
  end
end

::Float.__send__(:include, Mongoid::Extensions::Float)
::Float.__send__(:extend, Mongoid::Extensions::Float::ClassMethods)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongoid-3.0.5 lib/mongoid/extensions/float.rb
mongoid-3.0.4 lib/mongoid/extensions/float.rb
mongoid-3.0.3 lib/mongoid/extensions/float.rb
mongoid-3.0.2 lib/mongoid/extensions/float.rb
mongoid-3.0.1 lib/mongoid/extensions/float.rb
mongoid-3.0.0 lib/mongoid/extensions/float.rb