{ "info": { "author": "Alex Ward", "author_email": "alxwrd@googlemail.com", "bugtrack_url": null, "classifiers": [], "description": "# Coinhandler :moneybag:\n\n> A Python module to handle interacting with coins\n\n[![Build Status](https://travis-ci.com/alxwrd/coinhandler.svg?branch=master)](https://travis-ci.com/alxwrd/coinhandler)\n\n```python\n>>> from coinhandler import CoinHandler\n\n>>> handler = CoinHandler(\n... starting_float=(2.00, 1.00, 0.50, 0.20, 0.05)\n... )\n\n>>> handler.insert(0.50)\n>>> handler.insert(1.00)\n\n>>> handler.purchase(1.25)\n\n>>> handler.return_coins()\nCoinCollection(TwentyPence(1), FivePence(1))\n```\n\n## Installation\n\n### [pipenv](https://github.com/pypa/pipenv)*\n\n```shell\npipenv install coinhandler\n```\n\n### [pip](https://pypi.org/project/coinhandler)\n\n```shell\npip install coinhandler\n```\n\n### From source\n```shell\npip install git+git://github.com/alxwrd/coinhandler.git\n```\n\n> _*recommended_\n\n\n## Useage\n\n### CoinHandler\n\nA `CoinHandler` object can be used to manage a transaction, or a series\nof transactions. To create a handler instance, it should be provided\nwith a starting [float](https://en.wikipedia.org/wiki/Float_(money_supply))\n(money supply).\n\nThe `starting_float` should be an _iterable_ of either `float` or `int`\n\n```python\nfrom coinhandler import CoinHandler\n\nhandler = CoinHandler(\n starting_float=(2.00, 1.00, 0.50, 0.20, 0.05)\n)\n```\n\nA `CoinHandler` object provides a simple interface for making trasactions\nagainst the float it started with.\n\n#### `.available_coins` -> [`CoinCollection`](#coincollection)\n\nProvides access to the current supply of `Coin`s in in the handler.\n\n```python\n>>> handler.available_coins\nCoinCollection(TwoPound(1), OnePound(1), FiftyPence(1), TwentyPence(20), FivePence(5))\n```\n\n#### `.current_transaction` -> [`Transaction`](#transaction)\n\nProvides access to the `Coin`s that are part of the current transaction.\n\n```python\n>>> handler.insert(0.50)\n>>> handler.current_transaction\nTransaction(FiftyPence(1))\n```\n\n#### `.total()` -> `float`\n\nReturns the handlers current total value as a float.\n\n```python\n>>> handler.total()\n3.75\n```\n\nAlso equivalent to:\n\n```python\n>>> handler.available_coins.total() / 100\n3.75\n```\n\n#### `.insert(` _`value`_ `)`\n\nAdd a coin of _value_ to the `current_transaction`.\n\n```python\n>>> handler.insert(0.50)\n>>> handler.current_transaction\nTransaction(FiftyPence(1))\n```\n\n#### `.purchase(` _`value`_ `)`\n\nMoves the coins from `current_transaction` into the `available_coins` and\nmakes the difference in coins between the purchase _value_ and the\n`current_transation.total()` available in `.current_transaction`.\n\n```python\n>>> handler.available_coins\nCoinCollection(TwentyPence(1), FivePence(1))\n\n>>> handler.insert(0.50)\n>>> handler.purchase(0.25)\n\n>>> handler.current_transaction\nTransaction(TwentyPence(1), FivePence(1))\n>>> handler.available_coins\nCoinCollection(FiftyPence(1))\n```\n\n#### `.return_coins()` -> [`CoinCollection`](#coincollection)\n\nEmpties out the `current_transaction` and returns those coins as a\n`CoinCollection`.\n\n\n\n### CoinCollection\n\nA `CoinCollection` object represents a collection of `Coin`s. It functions\nsimilar to a python `list`, and provides some similar methods.\n\n\n```python\nfrom coinhandler import CoinCollection\n\ncollection = CoinCollection(2.00, 1.00, 0.50)\n```\n\nYou can also create a `CoinCollection` from a value. This will return the\nsmallest amount of `Coin`s needed to create that value.\n\n```python\n>>> CoinCollection.from_value(1.25)\nCoinCollection(OnePound(1), TwentyPence(1), FivePence(1))\n```\n\n#### `Transaction`\n\nA `Transaction` object is a subclass of `CoinCollection`, and functions\nidentically.\n\n\n#### `.remove_by_value(` _`value`_ `)` -> [`CoinCollection`](#coincollection)\n\nRemoves coins from the collection by a value, and returns new collection\nwith valid coins from the original collection.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.20, 0.05)\n>>> collection.remove_by_value(1.25)\nCoinCollection(OnePound(1), TwentyPence(1), FivePence(1))\n```\n\n> NOTE: `.remove_by_value` will only remove available coins from\n> the original collection. So for the example:\n> ```python\n> >>> collection = CoinCollection(2.00, 1.00, 0.20, 0.05)\n> >>> collection.remove_by_value(1.30)\n> CoinCollection(OnePound(1), TwentyPence(1), FivePence(0.05))\n> ```\n> Only '`1.25`' is returned.\n\n#### `.total()`\n\nReturns the total value of the collection as a _float_.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> coins.total()\n3.75\n```\n\n\n#### `.append(` _`value`_ `)`\n\nAdds the _value_ to the collection.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> collection.append(1.00)\n>>> collection.total()\n4.50\n```\n\n\n#### `.extend(` _`iterable[values]`_ `)`\n\nExtends the collection by an _iterable_ of _values_.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> collection.extend([1.00, 1.00])\n>>> collection.total()\n5.50\n```\n\n\n#### `.remove(` _`value`_ `)`\n\nRemoves a `Coin` represented by _value_ from the collection.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> collection.remove(1.00)\n>>> collection.total()\n2.50\n```\n\n\n#### `.clear()` -> [`CoinCollection`](#coincollection)\n\nRemoves all `Coin`s from the collection, and returns them as a new collection.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> coins = collection.clear()\n>>> collection.total()\n0.0\n>>> coins.total()\n3.50\n```\n\n\n#### `.pop(` _`index=-1`_ `)` -> [`Coin`](#coin)\n\nRemoves the `Coin` located _index_ out of the collection and returns it.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> collection.pop()\nFiftyPence(1)\n>>> collection.pop(0)\nTwoPound(1)\n>>> coins.total()\n1.00\n```\n\n\n#### As a _list_\n\nFor basic useage, a `CoinCollection` can be [_duck typed_](https://en.wikipedia.org/wiki/Duck_typing)\nas a list. It can be:\n\nCompared to an _iterable_ of _values_,\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> assert collection = [2.00, 1.00, 0.50]\n>>> assert collection = (2.00, 1.00, 0.50)\n```\n\nIterated over,\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> for coin in collection:\n... print(coin)\n'\u00a32.00'\n'\u00a31.00'\n'50p'\n```\n\nAnd accessed by index.\n\n```python\n>>> collection = CoinCollection(2.00, 1.00, 0.50)\n>>> collection[1]\nOnePound(1)\n```\n\n\n\n### Coin\n\nA `Coin` object represents a _value_. Its use allows representing money\nusing _int_ vs. _float_.\n\nThe `Coin` class is a factory class for all other _Coins_ that have been defined.\nIt will return the highest value coin of a given _value_.\n\n```python\nfrom coinhandler import Coin\nfrom coinhandler.coins import OnePound, FiftyPence\n\nassert Coin(100) == OnePound(1)\nassert Coin(50) == FiftyPence(1)\n```\n\nWhen using the `Coin` factory class, a valid coin _value_ should be used. Not doing so\ncan create undesirable `Coin` objects.\n\n```python\n>>> coin = Coin(23)\nOnePence(23)\n\n# Use a CoinColletion instead!\n\n>>> CoinCollection.from_value(23)\nCoinCollection(TwentyPence(1), TwoPence(1), OnePence(1))\n```\n\n_Coins_ of a specfic type can be created by just by creating an instance of them.\n\n```python\n>>> from coinhandler.coins import OnePound\n>>> OnePound()\nOnePound()\n```\n\nAll coins have a value, which is the represented as an _integer_.\n\n```python\n>>> from coinhandler.coins import OnePound\n>>> OnePound().value\n100\n```\n\nSubclassing from `Coin` will add that coin to the available coins to be created.\n\n```python\n>>> from coinhandler import Coin\n>>> Coin(25)\nFivePence(25)\n\n>>> class Quarter(Coin):\n... multiplier = 25\n... def __str__(self):\n... return f\"{self.value}\u00a2\"\n>>> coin = Coin(25)\n>>> print(coin)\n'25\u00a2'\n>>> coin.value\n25\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/alxwrd/coins", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "coinhandler", "package_url": "https://pypi.org/project/coinhandler/", "platform": "", "project_url": "https://pypi.org/project/coinhandler/", "project_urls": { "Bug Reports": "https://github.com/alxwrd/coinhandler/issues", "Homepage": "https://github.com/alxwrd/coins", "Source": "https://github.com/alxwrd/coinhandler" }, "release_url": "https://pypi.org/project/coinhandler/0.3/", "requires_dist": null, "requires_python": ">=3.6", "summary": "A Python module to handle interacting with coins", "version": "0.3" }, "last_serial": 4276932, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "6943e4974fcb952c6928d7c5cd055315", "sha256": "d4783780eb9c727557397da33d9ccc3996d79e6309c47ad77ebdf44fcb1ced3e" }, "downloads": -1, "filename": "coinhandler-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6943e4974fcb952c6928d7c5cd055315", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 8415, "upload_time": "2018-09-16T15:57:44", "url": "https://files.pythonhosted.org/packages/95/8e/c31105df40d380b78aa37886e43a384b10aefb06846107c3b47ffb09f515/coinhandler-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b609cca5511083f99d0e66eb768f88a5", "sha256": "40c10d79fd98d6c9ef4863788b25c4b43042a1ad1a301a85c6733782a9049534" }, "downloads": -1, "filename": "coinhandler-0.1.tar.gz", "has_sig": false, "md5_digest": "b609cca5511083f99d0e66eb768f88a5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5321, "upload_time": "2018-09-16T15:57:45", "url": "https://files.pythonhosted.org/packages/68/51/0274820e954a77df6e8a0e83c0e25da68bbf571dc0eb893c5bdff5068ad5/coinhandler-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "780c6142490038e1fc093c14f57a5247", "sha256": "06b5401f73ecbe1dcde34e8435f65d11632da26f72c0b4edea2c0e13191c1bb2" }, "downloads": -1, "filename": "coinhandler-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "780c6142490038e1fc093c14f57a5247", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 8413, "upload_time": "2018-09-16T16:00:18", "url": "https://files.pythonhosted.org/packages/b9/d7/1f3ae23565f7ae7bf330c5f9f72105720e38bfac87fdd86d1f4a6fee7b6a/coinhandler-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9c86269122dd4ee73eda749bae392941", "sha256": "609574bbe039a3abd079715e7bd974d36a2e127196173ab79d386a435378a766" }, "downloads": -1, "filename": "coinhandler-0.2.tar.gz", "has_sig": false, "md5_digest": "9c86269122dd4ee73eda749bae392941", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5319, "upload_time": "2018-09-16T16:00:19", "url": "https://files.pythonhosted.org/packages/94/be/fbcf5e967e41ba75fcd4a0087cfb9625055e802691c30d606c90b6fd1f7d/coinhandler-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "6547ffb80a4a2f6c9b8780ef2e5ec104", "sha256": "eb98c048077eb93cadd3c5c3763c779df1fa92bc34d24e0b142b14c09dc22b47" }, "downloads": -1, "filename": "coinhandler-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "6547ffb80a4a2f6c9b8780ef2e5ec104", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5515, "upload_time": "2018-09-16T16:06:57", "url": "https://files.pythonhosted.org/packages/5e/e5/a51536c120a6aba48b395dad2ef1fc21f49eb3152d8d824520d93aca6414/coinhandler-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4293427a959fd63d4d318fa67ec01531", "sha256": "8df8705e7ad13e1e4974a142fcdd807ac63f53d5277175de9e8a42c0857f81fe" }, "downloads": -1, "filename": "coinhandler-0.3.tar.gz", "has_sig": false, "md5_digest": "4293427a959fd63d4d318fa67ec01531", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5318, "upload_time": "2018-09-16T16:06:59", "url": "https://files.pythonhosted.org/packages/cd/56/e1b803e4ea9f885d27b58d9b0415de597ccf483eaa8803d1edd3a3d41b72/coinhandler-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6547ffb80a4a2f6c9b8780ef2e5ec104", "sha256": "eb98c048077eb93cadd3c5c3763c779df1fa92bc34d24e0b142b14c09dc22b47" }, "downloads": -1, "filename": "coinhandler-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "6547ffb80a4a2f6c9b8780ef2e5ec104", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5515, "upload_time": "2018-09-16T16:06:57", "url": "https://files.pythonhosted.org/packages/5e/e5/a51536c120a6aba48b395dad2ef1fc21f49eb3152d8d824520d93aca6414/coinhandler-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4293427a959fd63d4d318fa67ec01531", "sha256": "8df8705e7ad13e1e4974a142fcdd807ac63f53d5277175de9e8a42c0857f81fe" }, "downloads": -1, "filename": "coinhandler-0.3.tar.gz", "has_sig": false, "md5_digest": "4293427a959fd63d4d318fa67ec01531", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5318, "upload_time": "2018-09-16T16:06:59", "url": "https://files.pythonhosted.org/packages/cd/56/e1b803e4ea9f885d27b58d9b0415de597ccf483eaa8803d1edd3a3d41b72/coinhandler-0.3.tar.gz" } ] }