Sha256: 49570ac41d3058a2edd93cad978c131a9f232cdcf5d910d9c60d06d87cc9697f

Contents?: true

Size: 841 Bytes

Versions: 14

Compression:

Stored size: 841 Bytes

Contents

module Coercible
  class Coercer

    # Coerce BigDecimal values
    class Decimal < Numeric
      primitive ::BigDecimal

      FLOAT_FORMAT = 'F'.freeze

      # Coerce given value to String
      #
      # @example
      #   coercer[BigDecimal].to_string(BigDecimal('1.0')) # => "1.0"
      #
      # @param [BigDecimal] value
      #
      # @return [String]
      #
      # @api public
      def to_string(value)
        value.to_s(FLOAT_FORMAT)
      end

      # Passthrough the value
      #
      # @example
      #   Coercible::Coercion::BigDecimal.to_decimal(BigDecimal('1.0')) # => BigDecimal('1.0')
      #
      # @param [BigDecimal] value
      #
      # @return [Fixnum]
      #
      # @api public
      def to_decimal(value)
        value
      end

    end # class BigDecimal

  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/decimal.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.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/decimal.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/decimal.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/decimal.rb
coercible-1.0.0 lib/coercible/coercer/decimal.rb
coercible-0.2.0 lib/coercible/coercer/decimal.rb
coercible-0.1.0 lib/coercible/coercer/decimal.rb
coercible-0.0.2 lib/coercible/coercer/decimal.rb
coercible-0.0.1 lib/coercible/coercer/decimal.rb