Module: CMDx::Coercions::Rational
Overview
Converts various input types to Rational format
Handles conversion from strings, numbers, and other values to rational numbers using Ruby’s Rational() method. Raises CoercionError for values that cannot be converted to rational numbers.
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ Rational
Converts a value to a Rational.
Instance Method Details
#call(value, options = {}) ⇒ Rational
Converts a value to a Rational
38 39 40 41 42 43 |
# File 'lib/cmdx/coercions/rational.rb', line 38 def call(value, = {}) Rational(value) rescue ArgumentError, FloatDomainError, RangeError, TypeError, ZeroDivisionError type = Locale.t("cmdx.types.rational") raise CoercionError, Locale.t("cmdx.coercions.into_a", type:) end |