Sha256: b4e97c2d3907cbd09e31fcecd721afd031cb9b9ff1504442b94ed2ff59d9c98a

Contents?: true

Size: 547 Bytes

Versions: 4

Compression:

Stored size: 547 Bytes

Contents

require 'bigdecimal'

module Attributor

  class BigDecimal
    include Type

    def self.native_type
      return ::BigDecimal
    end

    def self.example(context=nil, **options)
      return ::BigDecimal.new("#{/\d{3}/.gen}.#{/\d{3}/.gen}")
    end

    def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **options)
      return nil if value.nil?
      return value if value.is_a?(self.native_type)
      if value.kind_of?(::Float)
        return BigDecimal(value, 10)
      end
      return BigDecimal(value)
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
attributor-2.6.0 lib/attributor/types/bigdecimal.rb
attributor-2.5.0 lib/attributor/types/bigdecimal.rb
attributor-2.4.0 lib/attributor/types/bigdecimal.rb
attributor-2.3.0 lib/attributor/types/bigdecimal.rb