{"id":26509760,"url":"https://github.com/readysteady/percentage","last_synced_at":"2025-04-05T20:08:13.041Z","repository":{"id":5711025,"uuid":"6922039","full_name":"readysteady/percentage","owner":"readysteady","description":"Ruby gem for working with percentages","archived":false,"fork":false,"pushed_at":"2025-01-02T12:27:57.000Z","size":53,"stargazers_count":32,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T20:37:33.439Z","etag":null,"topics":["bigdecimal","percentage","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/percentage","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/readysteady.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2012-11-29T13:56:42.000Z","updated_at":"2025-01-02T12:28:02.000Z","dependencies_parsed_at":"2024-10-22T16:36:27.709Z","dependency_job_id":null,"html_url":"https://github.com/readysteady/percentage","commit_stats":{"total_commits":101,"total_committers":4,"mean_commits":25.25,"dds":0.03960396039603964,"last_synced_commit":"36dadf76ce2da91999b4251f9eaa82413105824f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fpercentage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fpercentage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fpercentage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fpercentage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/readysteady","download_url":"https://codeload.github.com/readysteady/percentage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393570,"owners_count":20931813,"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":["bigdecimal","percentage","ruby"],"created_at":"2025-03-21T01:36:11.732Z","updated_at":"2025-04-05T20:08:13.010Z","avatar_url":"https://github.com/readysteady.png","language":"Ruby","readme":"# percentage\n\n![Gem Version](https://badge.fury.io/rb/percentage.svg)\n![Test Status](https://github.com/readysteady/percentage/actions/workflows/test.yml/badge.svg)\n\n\nRuby gem for working with percentages.\n\n\n## Install\n\nUsing Bundler:\n\n    $ bundle add percentage\n\nUsing RubyGems:\n\n    $ gem install percentage\n\n\n## Constructing Percentages\n\nThe `Percentage` method converts numeric objects to percentage objects\nwith values that you would expect:\n\n```ruby\nPercentage(50)  # =\u003e 50%\n\nPercentage(BigDecimal('17.5'))  # =\u003e 17.5%\n\nPercentage(Rational(25, 2))  # =\u003e 12.5%\n```\n\nPercentage objects can also be constructed directly, but in this case\nBigDecimal/Rational values are treated as fractions:\n\n```ruby\nPercentage.new(50)  # =\u003e 50%\n\nPercentage.new(BigDecimal('0.175'))  # =\u003e 17.5%\n\nPercentage.new(Rational(1, 8))  # =\u003e 12.5%\n```\n\nSome shortcut methods are defined on Integer and BigDecimal for convenience:\n\n```ruby\n50.percent  # =\u003e 50%\n\n5.as_percentage_of(10)  # =\u003e 50.0%\n\nBigDecimal('2.9').to_percentage  # =\u003e 2.9%\n```\n\n\n## Numeric features\n\nAs with other numerics, percentage objects are conceptually immutable.\nCommon numeric functionality like `to_i`, `to_f`, `to_s`, `to_r`, `zero?`,\nand equality/comparison methods are defined.\n\nPercentages can be added together:\n\n```ruby\nPercentage(10) + Percentage(20)  # =\u003e 30%\n```\n\nThey can also be \"scaled up\" using the `scale` method:\n\n```ruby\nPercentage(10).scale(5)  # =\u003e 50%\n```\n\nMultiplication is defined using the fractional value of the percentage.\nBigDecimal objects can't be coerced into rational objects, so the\nmultiplication order will matter in some cases, for example:\n\n```ruby\nPercentage(50) * 10  # =\u003e (5/1)\n\nPercentage(50) * Percentage(10)  # =\u003e 5.0%\n\nBigDecimal('150.00') * Percentage(50)  # =\u003e BigDecimal('75.00')\n\nPercentage(50) * BigDecimal('150.00')  # raises TypeError\n```\n\n\n## Bonus extras\n\nThere's a #percent_of method defined on Integer and BigDecimal for percentage calculations:\n\n```ruby\n50.percent_of(BigDecimal(150))  # =\u003e BigDecimal('75.00')\n\n10.percent_of(100)  # =\u003e (10/1)\n\nBigDecimal('0.5').percent_of(88)  # =\u003e BigDecimal('0.44')\n```\n\nThere's also a `Percentage.change` method for calculating the percentage change between two values:\n\n```ruby\nPercentage.change(2, 3)  # =\u003e 50.0%\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freadysteady%2Fpercentage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freadysteady%2Fpercentage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freadysteady%2Fpercentage/lists"}