{"id":19059953,"url":"https://github.com/q-m/nutriscore-ruby","last_synced_at":"2026-05-12T20:30:17.046Z","repository":{"id":56885952,"uuid":"193536495","full_name":"q-m/nutriscore-ruby","owner":"q-m","description":"nutriscore computation for Ruby","archived":false,"fork":false,"pushed_at":"2022-06-07T13:21:27.000Z","size":33,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-02T17:40:33.486Z","etag":null,"topics":["food-products","nutri-score","nutrients","nutriscore","nutrition","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/q-m.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}},"created_at":"2019-06-24T15:58:30.000Z","updated_at":"2022-05-16T09:26:24.000Z","dependencies_parsed_at":"2022-08-20T13:50:56.644Z","dependency_job_id":null,"html_url":"https://github.com/q-m/nutriscore-ruby","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fnutriscore-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fnutriscore-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fnutriscore-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fnutriscore-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/q-m","download_url":"https://codeload.github.com/q-m/nutriscore-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240114326,"owners_count":19749837,"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":["food-products","nutri-score","nutrients","nutriscore","nutrition","ruby","ruby-gem"],"created_at":"2024-11-09T00:12:16.340Z","updated_at":"2026-05-12T20:30:16.991Z","avatar_url":"https://github.com/q-m.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nutriscore\n\n[![Gem Version](https://badge.fury.io/rb/nutriscore.svg)](https://rubygems.org/gems/nutriscore)\n\nConsumer food products in some countries have a nutritional score, indicating\nhow healthy the product is to eat. Each country has its own approach, but in\nthe European Union the _Nutri-Score_ in several countries.\n\nThis gem implements the Nutri-Score for Ruby and includes adaptations for different\ncountries. The maintainer would be open to integrating other nutritional scores as well.\n\n_**Note:** this is currently under development, the API may change without notice,\nand scoring has not yet been fully verified. Be very careful using this in production._\n\n## Nutri-Score\n\nThere are currently two versions of the Nutri-Score in use. The first was\n[developed](https://www.food.gov.uk/business-guidance/nutrient-profiling-model-for-children)\nin the UK by the Food Standards Agency and\n[currently maintainted](https://www.gov.uk/government/publications/the-nutrient-profiling-model)\nby the Department of Health. It is used for regulating food advertisements.\n\nIn France, an adapted\n[Nutri-Score](https://www.santepubliquefrance.fr/Sante-publique-France/Nutri-Score)\nwas adopted in 2017 for use as a voluntary label on the packaging.\nIn 2018, Belgium and Spain adopted the same scheme.\n\nOther countries are evaluating adopting the Nutri-Score as well, including\nThe Netherlands. There was also a\n[European citizen's initiative](http://ec.europa.eu/citizens-initiative/public/initiatives/ongoing/details/2019/000008_en)\nto adopt it Europe-wide, but this has been withdrawn.\n\n## Installation\n\n```\ngem install nutriscore\n```\n\n## Usage\n\nThe input for all nutritional scores are a product category and nutritional values.\nWhich nutrients are required depends on the product category. Note that `fvnp` stands\nfor the amount of fruits, vegetables, nuts and pulses (and, since Oct 2019, also\nrapeseed, walnuts and olive oils).\n\n```ruby\nrequire 'nutriscore'\n\n# Fruit fromage frais\nproduct_a = {\n  energy: 459,          # kJ/100g\n  fat_saturated: 1.8,   #  g/100g\n  sugar: 13.4,          #  g/100g\n  sodium: 0.1,          #  g/100g\n  fvnp: 8,              #  g/100g (= weight-%)\n  fibres: 0.6,          #  g/100g\n  proteins: 6.5,        #  g/100g\n}\n\n# Compute the french Nutri-Score for a generic product.\nscore = Nutriscore::FR::SpecificScore.new(product_a)\n#\u003cNutriscore::FR::SpecificScore score=0\n#  positive_score=#\u003cNutriscore::FR::PositiveScore score=4\n#                    fvnp=0 fibres=0 proteins=4\u003e\n#  negative_score=#\u003cNutriscore::FR::NegativeScore score=4\n#                    energy=1 fat_saturated=1 sugar=2 sodium=0\u003e\u003e\nscore.score.single\n# =\u003e 0\nscore.score_class.single\n# =\u003e \"B\"\n```\n\nTo be able to work with incomplete information, results are returned as ranges.\nThe use of `.single` in the above example converts these to a single value (it\nreturns `nil` if there is not enough information to get a single result). The\nfollowing example shows what happens when data is missing.\n\n```ruby\nscore = Nutriscore::FR::SpecificScore.new(product_a.merge({ sodium: nil }))\nscore.score\n# =\u003e 0..10\nscore.score.single\n# =\u003e nil\nscore.score_class\n# =\u003e \"B\"..\"C\"\nscore.score_class.single\n# =\u003e nil\n```\n\nPlease only use `#single` and the regular Ruby `Range` methods on `#score` and `#score_class`.\nOther methods do exist, but are not guaranteed to be stable across releases.\n\nDifferent categories can use different score classes:\n* `Nutriscore::FR::CheeseScore` for cheese\n* `Nutriscore::FR::FatsScore` for vegetable and animal oils and fats\n* `Nutriscore::FR::MineralWaterScore` for mineral water\n* `Nutriscore::FR::DrinksScore` for other drinks\n* `Nutriscore::FR::SpecificScore` for other food products\n\nNote that the score classes may use different nutrients (there is one additional nutrient,\n`fat_total`, used by `FatsScore`).\n\n## UK\n\nThe UK has the same basis for computation, but it is used to determine\nwhether a product can be advertised (it must not be less healthy).\n\n```ruby\nscore = Nutriscore::UK::SpecificScore.new(product_a)\nscore.score\n# =\u003e 0\nscore.less_healthy?\n# =\u003e false\n```\n\nThe method `#less_healthy?` is UK-specific, and returns `true`, `false`, or `nil`\nif there is not enough information to make a judgement.\n\nBy default, the fibres measurement method is AOAC (which is preferred), but\nit is possible to use fibres values measured with the NSP method:\n\n```ruby\n# Acceptable values for the fibres_method are: :aoac and :nsp.\nscore = Nutriscore::UK::SpecificScore.new(product_a, fibres_method: :nsp)\n```\n\nDifferent categories can use different score classes:\n* `Nutriscore::UK::SpecificScore` for food products\n* `Nutriscore::UK::DrinksScore` for drinks\n\n## License\n\nThis software is distributed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fq-m%2Fnutriscore-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fq-m%2Fnutriscore-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fq-m%2Fnutriscore-ruby/lists"}