• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

RubyMoney/google_currency: Ruby Money::Bank interface for the Google Currency ex ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

RubyMoney/google_currency

开源软件地址(OpenSource Url):

https://github.com/RubyMoney/google_currency

开源编程语言(OpenSource Language):

HTML 72.9%

开源软件介绍(OpenSource Introduction):

ARCHIVED

Google's Finance Converter is no more. This exists only for historical purposes. Please see below for alternatives.

Google Currency

Build Status

This gem extends Money::Bank::VariableExchange with Money::Bank::GoogleCurrency and gives you access to the current Google Currency exchange rates.

Warning

This gem relies on Google's Finance Converter, which is getting deprecated without a known replacement. The network failures you might be getting are most likely the result of the deprecation. Use at your own risk!

Here's a list of alternative currency converters that you might wanna use instead — https://github.com/RubyMoney/money#implementations.

Usage

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.

Caveats

This gem uses Google Finance Converter under the hood.

Exchange rates are,

  1. Based on 1 unit of the original currency.
  2. Have a precision of 4 decimal places.

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

Copyright (c) 2011 Shane Emmons. See LICENSE for details.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap