{"id":16068283,"url":"https://github.com/tegon/money","last_synced_at":"2026-04-24T14:05:55.075Z","repository":{"id":71698285,"uuid":"81202287","full_name":"tegon/money","owner":"tegon","description":"Currency conversion library","archived":false,"fork":false,"pushed_at":"2017-03-01T15:02:37.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T23:32:47.975Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tegon.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-07T11:46:41.000Z","updated_at":"2020-04-15T02:22:50.000Z","dependencies_parsed_at":"2023-03-13T20:19:50.700Z","dependency_job_id":null,"html_url":"https://github.com/tegon/money","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"1eaa1bf2efb9fa97892c221cfd63415a09e29443"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tegon","download_url":"https://codeload.github.com/tegon/money/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243004121,"owners_count":20220237,"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-09T06:20:37.110Z","updated_at":"2026-04-24T14:05:55.041Z","avatar_url":"https://github.com/tegon.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# money\nCurrency conversion library\n\n[![Build Status](https://travis-ci.org/tegon/money.svg?branch=master)](https://travis-ci.org/tegon/money)\n\n# Usage\n---\n\n### Configuration\n\nFirst you have to configure the base currency and conversion rates.\n\n```ruby\nMoney.conversion_rates(String, Hash)\n```\n\n#### Example\n\n```ruby\nMoney.conversion_rates('BRL', 'USD' =\u003e 3.12, 'EUR' =\u003e 3.34)\n```\n\n### Constructor\n\nThe constructor accepts two arguments, the amount and the currency:\n\n```ruby\nmoney = Money.new(Numeric, String)\n```\n\n#### Example\n\n```ruby\nmoney = Money.new(50, 'BRL')\nmoney = Money.new(55.50, 'BRL')\n```\n\n# Methods\n---\n\n### #convert_to\n\nThis method returns a new `Money` instance with the currency passed as argument.\n\n```ruby\nnew_money = money.convert_to(String)\n```\n\n#### Example\n\n```ruby\nnew_money = money.convert_to('USD')\n=\u003e \"156.00 USD\"\n```\n\nIf you pass an unknown currency, you'll get a error:\n\n```ruby\nnew_money = money.convert_to('CAD')\n=\u003e \"Money::ConversionRateMissingError: Missing conversion rate for currency: CAD. Please set it using Money.conversion_rates\"\n```\n\nThe following arithmetic operations are supported:\n\n### Sum\n\n```ruby\nsum = money + other_money\n```\n\n#### Example\n\n```ruby\nsum = Money.new(10, 'BRL') + Money.new(50, 'BRL')\n=\u003e \"60.00 BRL\"\nsum = Money.new(10, 'BRL') + Money.new(50, 'USD')\n=\u003e \"166.00 BRL\"\n```\n\n### Subtraction\n\n```ruby\nsubtraction = money - other_money\n```\n\n#### Example\n\n```ruby\nsubtraction = Money.new(50, 'BRL') - Money.new(10, 'BRL')\n=\u003e \"40.00 BRL\"\nsubtraction = Money.new(200, 'BRL') - Money.new(50, 'USD')\n=\u003e \"44.00 BRL\"\n```\n\n### Division\n\n```ruby\ndivision = money / Numeric\n```\n\n#### Example\n\n```ruby\ndivision = Money.new(50, 'BRL') / 2\n=\u003e \"25.00 BRL\"\n```\n\n### Multiplication\n\n```ruby\nmultiplication = money * Numeric\n```\n\n#### Example\n\n```ruby\nmultiplication = Money.new(50, 'BRL') * 2\n=\u003e \"100.00 BRL\"\n```\n\n### Comparisons\n\nThe comparisons are based on the money result. If a different currencies are used, the one on the right will be converted.\n\n\n#### Example\n\n```ruby\nMoney.new(156, 'BRL') == Money.new(156, 'BRL') # same amount, same currency, returns true\n=\u003e true\nMoney.new(156, 'BRL') == Money.new(50, 'USD') # different amount and currency, but 50 USD converted to BRL is 156, the result is true\n=\u003e true\nMoney.new(50, 'BRL') == Money.new(156, 'BRL') # same currency, different amount, returns false\n=\u003e false\nMoney.new(50, 'BRL') == Money.new(50, 'USD') # same currency, same amount, returns false (1 USD is 3.12 BRL)\n=\u003e false\nMoney.new(50, 'USD') \u003e Money.new(50, 'BRL') # 50 USD is 156 BRL\n=\u003e true\nMoney.new(50, 'USD') \u003c Money.new(50, 'BRL') # 50 USD is 156 BRL\n=\u003e false\n```\n\n# Development\n---\n\nYou need ruby version 1.9.3 or newer installed. After you've installed it, clone the repository with:\n\n```bash\ngit clone https://github.com/tegon/money\n```\n\nThen run the test suite to make sure everything is working correctly:\n\n```bash\ncd money\nrake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegon%2Fmoney","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftegon%2Fmoney","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegon%2Fmoney/lists"}