Sha256: 1021a821159e384c7258d3b7124d10468ac2f0d4b536917ee415ff810276903c

Contents?: true

Size: 852 Bytes

Versions: 18

Compression:

Stored size: 852 Bytes

Contents

module Virtus
  class Coercion

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

      FLOAT_FORMAT = 'F'.freeze

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

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

    end # class BigDecimal
  end # class Coercion
end # module Virtus

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
virtus-0.5.5 lib/virtus/coercion/decimal.rb
virtus-0.5.4 lib/virtus/coercion/decimal.rb
virtus-0.5.3 lib/virtus/coercion/decimal.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/lib/virtus/coercion/decimal.rb
virtus-0.5.2 lib/virtus/coercion/decimal.rb
virtus-0.5.1 lib/virtus/coercion/decimal.rb
virtus-0.5.0 lib/virtus/coercion/decimal.rb
virtus-0.4.2 lib/virtus/coercion/decimal.rb
virtus-0.4.1 lib/virtus/coercion/decimal.rb
virtus-0.4.0 lib/virtus/coercion/decimal.rb
virtus-0.3.0 lib/virtus/coercion/decimal.rb
virtus-0.2.0 lib/virtus/coercion/decimal.rb
virtus-0.1.0 lib/virtus/coercion/decimal.rb
virtus-0.0.10 lib/virtus/coercion/decimal.rb
virtus-0.0.9 lib/virtus/coercion/decimal.rb
virtus-0.0.8 lib/virtus/coercion/decimal.rb
virtus-0.0.7 lib/virtus/coercion/decimal.rb
virtus-0.0.6 lib/virtus/coercion/decimal.rb