Class: ActiveAttr::Typecasting::BigDecimalTypecaster
- Inherits:
-
Object
- Object
- ActiveAttr::Typecasting::BigDecimalTypecaster
- Defined in:
- lib/active_attr/typecasting/big_decimal_typecaster.rb
Overview
Typecasts an Object to a BigDecimal
Instance Method Summary collapse
-
#call(value) ⇒ BigDecimal?
Typecasts an object to a BigDecimal.
Instance Method Details
#call(value) ⇒ BigDecimal?
Typecasts an object to a BigDecimal
Attempt to convert using #to_d, else it creates a BigDecimal using the String representation of the value.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_attr/typecasting/big_decimal_typecaster.rb', line 27 def call(value) if value.is_a? BigDecimal value elsif value.is_a? Rational value.to_f.to_d elsif value.respond_to? :to_d value.to_d else BigDecimal.new value.to_s end end |