All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.coercible-1.0.0.lib.coercible.coercer.decimal.rb Maven / Gradle / Ivy

The newest version!
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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy