Module: CMDx::Coercions::BigDecimal
Overview
Coerces to ‘BigDecimal`. Default precision is 14 digits; override with `precision:` on the declaration.
Instance Method Summary collapse
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ BigDecimal, Coercions::Failure
15 16 17 18 19 20 21 22 |
# File 'lib/cmdx/coercions/big_decimal.rb', line 15 def call(value, = EMPTY_HASH) return value if value.is_a?(BigDecimal) BigDecimal(value, [:precision] || 14) rescue ArgumentError, TypeError type = I18nProxy.t("cmdx.types.big_decimal") Failure.new(I18nProxy.t("cmdx.coercions.into_a", type:)) end |