{"id":16073505,"url":"https://github.com/tegon/money.cr","last_synced_at":"2025-06-25T02:33:06.934Z","repository":{"id":71698298,"uuid":"83566419","full_name":"tegon/money.cr","owner":"tegon","description":"Currency conversion library","archived":false,"fork":false,"pushed_at":"2017-03-01T15:04:31.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T23:40:20.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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-03-01T14:55:56.000Z","updated_at":"2017-03-01T14:57:17.000Z","dependencies_parsed_at":"2023-06-04T06:12:16.450Z","dependency_job_id":null,"html_url":"https://github.com/tegon/money.cr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney.cr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney.cr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney.cr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegon%2Fmoney.cr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tegon","download_url":"https://codeload.github.com/tegon/money.cr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243004058,"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-09T08:20:56.385Z","updated_at":"2025-03-11T09:19:03.995Z","avatar_url":"https://github.com/tegon.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# money\n\nCurrency conversion library\n\n[![Build Status](https://travis-ci.org/tegon/money.cr.svg?branch=master)](https://travis-ci.org/tegon/money.cr)\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  money:\n    github: tegon/money.cr\n```\n\n# Usage\n---\n\n```crystal\nrequire \"money\"\n```\n\n### Configuration\n\nFirst you have to configure the base currency and conversion rates.\n\n```crystal\nMoney.conversion_rates(String, Hash of String =\u003e Float64)\n```\n\n#### Example\n\n```crystal\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```crystal\nmoney = Money.new(Float64, String)\n```\n\n#### Example\n\n```crystal\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```crystal\nnew_money = money.convert_to(String)\n```\n\n#### Example\n\n```crystal\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```crystal\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```crystal\nsum = money + other_money\n```\n\n#### Example\n\n```crystal\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```crystal\nsubtraction = money - other_money\n```\n\n#### Example\n\n```crystal\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```crystal\ndivision = money / Float64 | Int32\n```\n\n#### Example\n\n```crystal\ndivision = Money.new(50, \"BRL\") / 2\n=\u003e \"25.00 BRL\"\n```\n\n### Multiplication\n\n```crystal\nmultiplication = money * Float64 | Int32\n```\n\n#### Example\n\n```crystal\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```crystal\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\nYou need crystal version 0.18.7 or newer installed. After you've installed it, clone the repository with:\n\n```bash\ngit clone https://github.com/tegon/money.cr\n```\n\nThen run the test suite to make sure everything is working correctly:\n\n```bash\ncd money\ncrystal spec\n```\n\n# Contributing\n\n1. Fork it ( https://github.com/tegon/money.cr/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegon%2Fmoney.cr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftegon%2Fmoney.cr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegon%2Fmoney.cr/lists"}