{"id":17770415,"url":"https://github.com/gampleman/exchange_rates","last_synced_at":"2025-04-01T14:25:30.735Z","repository":{"id":12022858,"uuid":"14606457","full_name":"gampleman/exchange_rates","owner":"gampleman","description":"exchange_rates is a gem that allows currency conversion and rate history tracking.","archived":false,"fork":false,"pushed_at":"2015-07-01T09:36:15.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T23:36:18.313Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://exchange-rates.herokuapp.com/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gampleman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-22T02:21:16.000Z","updated_at":"2015-07-01T09:36:13.000Z","dependencies_parsed_at":"2022-09-17T11:02:36.789Z","dependency_job_id":null,"html_url":"https://github.com/gampleman/exchange_rates","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Fexchange_rates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Fexchange_rates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Fexchange_rates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gampleman%2Fexchange_rates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gampleman","download_url":"https://codeload.github.com/gampleman/exchange_rates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246653014,"owners_count":20812227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-26T21:22:52.024Z","updated_at":"2025-04-01T14:25:30.714Z","avatar_url":"https://github.com/gampleman.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExchangeRates\n\nExchangeRates is a Ruby Gem that allows currency conversion between a number of currencies and allows a historical overview of the currencies. It takes its information from the [European Central Banks historical feed](\nhttp://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml).\n\nA demo application can be seen running at http://exchange-rates.herokuapp.com and the source code is [available here](https://github.com/gampleman/exchange_rates/blob/master/example.rb).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'exchange_rates'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install exchange_rates\n\n## Usage\n\nThe first task that the programmer must use is to obtain the data source. The library assumes it will be in `./exchange-rates.xml`, however the path can be set via the environment variable `EXCHANGE_RATE_FILE`, which should point to the exchange rate file. This file can be downloaded from the [ECB website](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml).\n\nThe library will fetch this file automatically if not present, however it is your responsibility to\nmaintain this file as fresh as you need it. You can download a new version with\n`ExchangeRates.fetch_rates!`.\n\nFinally if you have a different datasource, you can simply parse it and call `ExchangeRates.set_rates(data, base_currency)`, where `data` will be your currency data organized by date and `base_currency` will be the currency code to which your rates are relative to. For example:\n\n    ExchangeRates.set_rates({\n       Date::civil(2013, 11, 21) =\u003e {\n        'EUR' =\u003e 0.9472,  # means 1 USD = 0.9472 EUR on the 21st Oct 2013\n        'JPY' =\u003e 135.83,\n        'BGN' =\u003e 1.9558,\n        'CZK' =\u003e 27.197\n      },\n      Date::civil(2013, 11, 20) =\u003e {\n        'EUR' =\u003e 0.9527,\n        'JPY' =\u003e 135.2,\n        'BGN' =\u003e 1.9558,\n        'CZK' =\u003e 27.329\n      }\n    }, 'USD')\n\nThen there are three methods you can call:\n\n#### at\n\n`ExchangeRates.at(date, from_currency, to_currency)` returns the exchange rate from `from_currency` to `to_currency` on the date `date`. Given the data above, the call `ExchangeRates.at(Date::civil(2013, 11, 20), 'JPY', 'CZK')` would return `0.202137574`.\n\nThe method throws exceptions if asked about missing dates/currencies.\n\n#### convert\n\n`ExchangeRates.convert(amount, opts)` converts an amount of money between currencies. The options for this method are:\n\n`:from` - from currency, defaults to base_currency (see above, for the default data this is EUR)  \n`:to`   - to currency, defaults to base_currency  \n`:date` - date at which to perform conversion, defaults to current date\n\n#### over_time\n\n`ExchangeRates.over_time(from, to)` gives a hash of all known dates and the exchange rate between `from` and `to`.\n\nAgain given the above data, calling `ExchangeRates.over_time('JPY', 'CZK')` gives `{Date::civil(2013, 11, 21) =\u003e 0.200228226, Date::civil(2013, 11, 20) =\u003e 0.202137574}`.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgampleman%2Fexchange_rates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgampleman%2Fexchange_rates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgampleman%2Fexchange_rates/lists"}