Skip to content

natural language parsing of recipe ingredients, making sense of amounts, units, and ingredients

Notifications You must be signed in to change notification settings

howells/ingreedy

This branch is 2 commits ahead of, 8 commits behind iancanderson/ingreedy:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

857a1e2 · Jan 15, 2020
Jan 15, 2020
Mar 8, 2016
Nov 18, 2013
Oct 28, 2013
Oct 18, 2015
Sep 13, 2016
Oct 17, 2015
Mar 13, 2016
Oct 18, 2015
Oct 18, 2015

Repository files navigation

Usage

result = Ingreedy.parse('1 lb. potatoes')
print result.amount
  #=> 1.0
print result.unit
  #=> :pound
print result.ingredient
  #=> "potatoes"

I18n and custom dictionaries

Ingreedy.dictionaries[:fr] = { 
  units: { dash: ['pincée'] }, 
  numbers: { 'une' => 1 }, 
  prepositions: ['de'] 
}

Ingreedy.locale = :fr # Also automatically follows I18n.locale if available

result = Ingreedy.parse('une pincée de sucre')
print result.amount
  #=> 1.0
print result.unit
  #=> :dash
print result.ingredient
  #=> "sucre"

Handling amounts

By default, Ingreedy will convert all amounts to a rational number:

result = Ingreedy.parse("1 1/2 cups flour")
print result.amount
  #=> 3/2

However, setting Ingreedy.preverse_amounts = true, will allow amounts to be detected and returned as originally input:

Ingreedy.preserve_amounts = true

result = Ingreedy.parse("1 1/2 cups flour")
print result.amount
  #=> 1 1/2

Live demo

Pieces of Flair

  • Gem Version
  • Build Status
  • Code Climate
  • Coverage Status

Development

Run the tests:

rspec spec

About

natural language parsing of recipe ingredients, making sense of amounts, units, and ingredients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%