{"id":21454914,"url":"https://github.com/zucchinidev/product_scanner","last_synced_at":"2025-08-20T16:20:31.489Z","repository":{"id":99765640,"uuid":"110381557","full_name":"zucchinidev/product_scanner","owner":"zucchinidev","description":"A product scanner created with Elixir, with the aim of continuing to learn.","archived":false,"fork":false,"pushed_at":"2017-11-11T21:25:47.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-11T08:51:28.607Z","etag":null,"topics":["elixir","elixir-lang","otp"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zucchinidev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2017-11-11T21:25:27.000Z","updated_at":"2017-11-11T21:29:01.000Z","dependencies_parsed_at":"2023-04-07T14:17:12.164Z","dependency_job_id":null,"html_url":"https://github.com/zucchinidev/product_scanner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zucchinidev/product_scanner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zucchinidev%2Fproduct_scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zucchinidev%2Fproduct_scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zucchinidev%2Fproduct_scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zucchinidev%2Fproduct_scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zucchinidev","download_url":"https://codeload.github.com/zucchinidev/product_scanner/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zucchinidev%2Fproduct_scanner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271347055,"owners_count":24743754,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","elixir-lang","otp"],"created_at":"2024-11-23T05:09:39.219Z","updated_at":"2025-08-20T16:20:31.482Z","avatar_url":"https://github.com/zucchinidev.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ProductScanner\n\n```\nCode         | Name                |  Price\n-------------------------------------------------\nVOUCHER      | Voucher             |   5.00€\nTSHIRT       | T-Shirt             |  20.00€\nMUG          | Coffee Mug          |   7.50€\n```\n\n\nVarious departments have insisted on the following discounts:\n\n* The marketing department believes in 2-for-1 promotions (buy two of the same product, get one free), and would like for there to be a 2-for-1 special on VOUCHER items.\n\n* The CFO insists that the best way to increase sales is with discounts on bulk purchases (buying x or more of a product, the price of that product is reduced), and demands that if you buy 3 or more TSHIRT items, the price per unit should be 19.00€.\n\nThe checkout process allows for items to be scanned in any order, and should return the total amount to be paid.\n\n## Getting Started\n\nTo start the scanner you can use:\n\n```elixir\n{:ok, pid} = ProductScanner.StateCreator.create() |\u003e ProductScanner.start_link()\n\nEnum.each([\"VOUCHER\", \"TSHIRT\", \"MUG\"], fn product -\u003e ProductScanner.scan(pid, product) end)\n\nstate = %Checkout{\n              available_discounters: DiscountsLoader.available_discounters(),\n              price_rules: DiscountRules.get_rules(),\n              scanned_products: ProductScanner.get_scanned_products(pid)\n            }\n\nCheckout.calculate_total_amount(state) // 32.50\n```\n\nDocumentation can be generated with:\n```\nmix docs\n```\n\n## Test Cases\n```elixir\n  defp get_test_cases do\n    [\n      %{scan_products: [], result: 0},\n      %{scan_products: [\"VOUCHER\", \"VOUCHER\", \"VOUCHER\"], result: 10},\n      %{scan_products: [\"VOUCHER\", \"TSHIRT\", \"MUG\"], result: 32.50},\n      %{scan_products: [\"VOUCHER\", \"TSHIRT\", \"VOUCHER\"], result: 25},\n      %{scan_products: [\"TSHIRT\", \"TSHIRT\", \"TSHIRT\", \"VOUCHER\", \"TSHIRT\"], result: 81},\n      %{scan_products: [\"VOUCHER\", \"TSHIRT\", \"VOUCHER\", \"VOUCHER\", \"MUG\", \"TSHIRT\", \"TSHIRT\"], result: 74.50}\n    ]\n  end\n\n#  Finished in 0.2 seconds\n#  22 tests, 0 failures\n\n```\n## Contributions\n\nIf you do make changes to the codebase, please make sure you test your changes thoroughly, and include any unit tests alongside new or changed behaviours.\n\n$ mix test","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzucchinidev%2Fproduct_scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzucchinidev%2Fproduct_scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzucchinidev%2Fproduct_scanner/lists"}