Sha256: 2d64b63b25635411ad90aac27d04f387d66e1366d089c611695b4fdfb8de0963

Contents?: true

Size: 854 Bytes

Versions: 14

Compression:

Stored size: 854 Bytes

Contents

module Coercible
  class Coercer

    # Coerce Float values
    class Float < Numeric
      primitive ::Float

      # Passthrough the value
      #
      # @example
      #   coercer[Float].to_float(1.0)  # => 1.0
      #
      # @param [Float] value
      #
      # @return [Integer]
      #
      # @api public
      def to_float(value)
        value
      end

      # Coerce given value to a DateTime
      #
      # @example
      #   datetime = Coercible::Coercion::Float.to_datetime(1000000000.999)  # => Sun, 09 Sep 2001 01:46:40 +0000
      #   datetime.to_f  # => 1000000000.999
      #
      # @param [Float] value
      #
      # @return [DateTime]
      #
      # @api public
      def to_datetime(value)
        ::DateTime.strptime((value * 10**3).to_s, "%Q")
      end

    end # class Float

  end # class Coercer
end # module Coercible

Version data entries

14 entries across 12 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/float.rb
coercible-1.0.0 lib/coercible/coercer/float.rb
coercible-0.2.0 lib/coercible/coercer/float.rb
coercible-0.1.0 lib/coercible/coercer/float.rb
coercible-0.0.2 lib/coercible/coercer/float.rb
coercible-0.0.1 lib/coercible/coercer/float.rb