{"id":16820205,"url":"https://github.com/dvandersluis/number_muncher","last_synced_at":"2025-03-17T15:24:38.839Z","repository":{"id":56885897,"uuid":"227191226","full_name":"dvandersluis/number_muncher","owner":"dvandersluis","description":"Tiny ruby library for parsing numbers","archived":false,"fork":false,"pushed_at":"2019-12-18T17:22:59.000Z","size":77,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-23T15:48:17.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/dvandersluis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-10T18:40:58.000Z","updated_at":"2019-12-18T17:22:45.000Z","dependencies_parsed_at":"2022-08-20T14:31:25.407Z","dependency_job_id":null,"html_url":"https://github.com/dvandersluis/number_muncher","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fnumber_muncher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fnumber_muncher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fnumber_muncher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fnumber_muncher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvandersluis","download_url":"https://codeload.github.com/dvandersluis/number_muncher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056432,"owners_count":20390720,"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-13T10:55:53.428Z","updated_at":"2025-03-17T15:24:38.814Z","avatar_url":"https://github.com/dvandersluis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NumberMuncher\n\n[![Build Status](https://travis-ci.org/dvandersluis/number_muncher.svg?branch=master)](https://travis-ci.org/dvandersluis/fractions)\n[![Gem Version](https://badge.fury.io/rb/number_muncher.svg)](https://badge.fury.io/rb/number_muncher)\n\nParses strings into numbers, including integers, decimals, and fractions (including unicode fraction glyphs like `⅐`). \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/muncher.jpg\" width=\"15%\" height=\"15%\"\u003e\n  \u003cbr/\u003e\n  \u003csup align=\"center\"\u003e\n    A \u003ca href=\"https://en.wikipedia.org/wiki/Munchers#Number_Munchers\"\u003eNumber Muncher\u003c/a\u003e\n  \u003c/sup\u003e\n\u003c/p\u003e\n\n## Usage\n\n### Formats\n\n`NumberMuncher` accepts the following formats (with an optional leading `-`):\n\n* Integers (with or without separators): `1`, `-1`, `5,394`, `9592`, etc.\n* Decimals (with or without separators): `3.5`, `-7.4`, `9,104.94`, etc.\n* Fractions: `3/5`, `-19/20`, `¾`, etc. (see [`unicode.rb`](lib/number_muncher/unicode.rb) for a full list of supported Unicode fraction glyphs).\n* Mixed fractions (with or without separators): `3 3/4`, `1-1/3`, `-1⅔`, `1,234 ⅚`, etc.\n\nOther inputs, including invalid fractions (eg. `1/0`), are considered invalid and will raise `NumberMuncher::InvalidNumber`.\n\n### Parsing\n\nParsing a numeric string for a single `Rational` (which can then have `to_i`, `to_f`, etc. called on it as per your needs):\n\n```ruby\nNumberMuncher.parse('4 1/2') #=\u003e 9/2r\n\n# or equivalent:\nNumberMuncher::Numeric.new('4 1/2') \n```\n\nIf the input string contains multiple numbers (other than mixed fractions), `NumberMuncher::InvalidParseExpression` will be raised.\n\n### Scanning\n\nReturns all the numbers in a string, as `Rational`s.\n\n```ruby\nNumberMuncher.scan('Cook at 375° for 10 minutes, flip and cook for another 5.5 minutes')\n# =\u003e [375r, 10r, 11/2r]\n```\n\n### Formatting\n\nReturns a fraction string for a given numeric value.\n\n```ruby\nNumberMuncher.to_fraction(1/4r) #=\u003e \"¼\"\nNumberMuncher.to_fraction(9.625) #=\u003e \"9⅝\"\n\n# Without using unicode glyphs:\nNumberMuncher.to_fraction(1/4r, unicode: false) #=\u003e \"1/4\"\nNumberMuncher.to_fraction(9.625, unicode: false) #=\u003e \"9 5/8\"\n\n# Rounding:\nNumberMuncher.to_fraction(3/7r, round_to: 1/4r) #=\u003e \"½\"\n\n# Rationalizing (adjust the fraction precision, default = 0.001):\nNumberMuncher.to_fraction(Math::PI) #=\u003e \"3 9/64\"\nNumberMuncher.to_fraction(Math::PI, factor: 0.1) #=\u003e \"3⅕\"\nNumberMuncher.to_fraction(Math::PI, factor: 0.0000000000000001) #=\u003e \"3 39854788871587/281474976710656\"  \n```\n\n`to_fraction` can also be called as an instance method. Note that this method does not take a `round_to` argument, but you can chain `round` before calling `to_fraction`:\n\n```ruby\nNumberMuncher.parse('3.456').to_fraction #=\u003e \"3 21/46\" \nNumberMuncher.parse('3.456').round(0.1).to_fraction #=\u003e \"3½\"\nNumberMuncher.parse('3.456').round(0.1).to_fraction(unicode: false) #=\u003e \"3 1/2\"\n```\n\n## Installation\n\n`NumberMuncher` requires ruby \u003e= 2.4.4.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'number_muncher'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install number_muncher\n\n## Configuration\n\nSeparators for thousands and decimals can be configured. Default values are shown below:\n\n```ruby\nNumberMuncher.thousands_separator = ','\nNumberMuncher.decimal_separator = '.'\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/dvandersluis/number_muncher.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fnumber_muncher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvandersluis%2Fnumber_muncher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fnumber_muncher/lists"}