Sha256: 734d8ae471bd04be7834277593062b1ff2c128e2160e28a85172935dce57a8cb

Contents?: true

Size: 492 Bytes

Versions: 2

Compression:

Stored size: 492 Bytes

Contents

require 'bigdecimal'

module Attributor
  class BigDecimal < Numeric
    def self.native_type
      ::BigDecimal
    end

    def self.example(_context = nil, options: {})
      BigDecimal("#{/\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?(native_type)
      return BigDecimal(value, 10) if value.is_a?(::Float)
      BigDecimal(value)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attributor-5.4 lib/attributor/types/bigdecimal.rb
attributor-5.3 lib/attributor/types/bigdecimal.rb