
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
github.com/RubyMoney/google_currency
Advanced tools
This gem extends Money::Bank::VariableExchange with Money::Bank::GoogleCurrency and gives you access to the current Google Currency exchange rates.
require 'money'
require 'money/bank/google_currency'
# (optional)
# set the seconds after than the current rates are automatically expired
# by default, they never expire
Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
# set default bank to instance of GoogleCurrency
Money.default_bank = Money::Bank::GoogleCurrency.new
# create a new money object, and use the standard #exchange_to method
money = Money.new(1_00, "USD") # amount is in cents
money.exchange_to(:EUR)
# or install and use the 'monetize' gem
require 'monetize'
money = 1.to_money(:USD)
money.exchange_to(:EUR)
An UnknownRate will be thrown if #exchange_to is called with a Currency
that Money knows, but Google does not.
An UnknownCurrency will be thrown if #exchange_to is called with a
Currency that Money does not know.
A GoogleCurrencyCaptchaError will be thrown if the Google Finance Converter API page responds with a Captcha instead of a rate (#52).
A GoogleCurrencyFetchError will be thrown if there is an unknown issue with the Google Finance Converter API.
This gem uses Google Finance Converter under the hood.
Exchange rates are,
What this means is that if the JPY to USD exchange rate is 0.0083660, Google will report the JPY to USD exchange rate as 0.0084. As a result, a larger JPY to USD conversion such as 10000 JPY to USD would yield 84 USD instead of 83.66 USD.
Consequently, this means that small exchange rates will be imprecise. For example, if the IDR to USD exchange rate were 0.00007761, Google will report it as 0.0001. This means 100000 IDR would exchange to 10 USD instead of 7.76 USD.
To accommodate for this, the reverse rate will be obtained if the rate is small (below 0.1) and the reciprocal of this reverse rate is used.
Copyright (c) 2011 Shane Emmons. See LICENSE for details.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.