module Sequel::CurrencyRateExchange
Public Instance Methods
exchange_to(currency, rates_table = :currency_rates)
click to toggle source
Exchange column value to a specific currency
@param currency [String] currency @param rates_table [Symbol] rates table name
@example
Sequel[:amount].exchange_to("EUR", :order_rates)
@return [Sequel::SQL::NumericExpression]
# File lib/sequel/extensions/currency_rates.rb, line 57 def exchange_to(currency, rates_table = :currency_rates) rate = Sequel[rates_table][:rates].pg_jsonb.get_text(currency).cast_numeric(Float) self * rate end
in_usd(*opts)
click to toggle source
Exchange column value to usd
@param opts (see exchange_to
)
@example
Sequel[:amount].in_usd
@return (see exchange_to
)
# File lib/sequel/extensions/currency_rates.rb, line 69 def in_usd(*opts) exchange_to("USD", *opts) end