Module: BetterRecord::ExchangeRateInteger
- Defined in:
- lib/better_record/exchange_rate_integer.rb
Defined Under Namespace
Modules: TableDefinition Classes: Type
Class Method Summary collapse
Class Method Details
.convert_to_exchange_rate(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/better_record/exchange_rate_integer.rb', line 9 def self.convert_to_exchange_rate(value) return StoreAsInt::ExchangeRate.new(0) unless value if (!value.kind_of?(Numeric)) begin exchange_rate_to_i = (value.gsub(/\%/, '').presence || 0).to_d * StoreAsInt::ExchangeRate.base StoreAsInt::ExchangeRate.new(exchange_rate_to_i.to_i) rescue StoreAsInt::ExchangeRate.new end else StoreAsInt::ExchangeRate.new(value) end end |