Sha256: 0a5ca9e4ae2d82eef1e7036e1aa15ad7ac69e0f15d5e14206ed94222f601c6c3
Contents?: true
Size: 802 Bytes
Versions: 9
Compression:
Stored size: 802 Bytes
Contents
# frozen_string_literal: true require 'date' require 'bigdecimal' require 'bigdecimal/util' require 'time' module Dry module Types module Coercions # JSON-specific coercions # # @api public module JSON extend Coercions # @param [#to_d, Object] input # # @return [BigDecimal,nil] # # @raise CoercionError # # @api public def self.to_decimal(input, &block) if input.is_a?(::Float) input.to_d else BigDecimal(input) end rescue ArgumentError, TypeError if block_given? yield else raise CoercionError, "#{input} cannot be coerced to decimal" end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems