Code Monkey home page Code Monkey logo

munchie's Introduction

Munchie

Munchie is a natural language food/diet log entry parser written in Ruby, inspired by the Chronic date/time parser. See below for examples of the wide variety of formats Munchie will parse.

Installation

$ gem install munchie

Usage

require 'munchie'

Munchie.parse('1 tbsp Olive Oil')
  #=> <Munchie::Food quantity=1 volume=<15ml>>

Munchie.parse('Derp')
  #=> nil

The parser will always return a Munchie::Food object with as many attributes as can be filled by extracting values from the original input string.

See Munchie.parse for detailed usage instructions.

Examples

Munchie can parse a huge variety of food log formats, from diet logs to recipes. Following is a small sample of strings that will be properly parsed.

  • ½ cup (70g) toasted hazelnuts, chopped
  • 1 cup (90g) chopped dark chocolate
  • 1¾ cups (255g) plain (all-purpose) flour, sifted
  • 1 teaspoon baking powder, sifted
  • 1 teaspoon bicarbonate of (baking) soda
  • 1 teaspoon ground cinnamon
  • ⅓ cup (115g) golden syrup
  • 6 bananas, peeled and chopped
  • 2 mangoes, peeled and chopped
  • 1 cup (280g) vanilla-flavoured yoghurt
  • 125g butter, softened
  • 1 cup (175g) brown sugar
  • 1 teaspoon vanilla extract
  • 2 eggs
  • 2 cups mashed banana
  • 1 cup (160g) frozen raspberries
  • ½ cup (25g) sweetened coconut flakes, plus extra, for sprinkling
  • 1¾ cups (255g) plain (all-purpose) flour, sifted

Contribute

If you'd like to hack on Chronic, start by forking the repo on GitHub:

https://github.com/jmartelletti/munchie

The best way to get your changes merged back is as follows:

  1. Clone your fork of this repository
  2. Create an appropriately named branch to work on your change
  3. Hack away
  4. Add tests and make sure everything still passes by running rake
  5. If you are adding new functionality, document it in the Readme
  6. Do not change the version number, we will do that at release time
  7. If necessary, rebase your commits into logical chunks, without errors
  8. Push the branch up to GitHub
  9. Send a pull request for your branch

munchie's People

Contributors

annorman avatar jmartelletti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

munchie's Issues

Parser chooses the incorrect tokens

"12 kg something" breaks into 4 tokens, but it considers 1 to be a quantity and 2 to be a unit so it returns: #Munchie::Food:0x007fedc1b0dab8 @tokens=[text: 1 something, text: something]

Also for some reason kg returns grams, even though the token parser works correctly:
Munchie.parse("1 kg something")
=> #Munchie::Food:0x007fedc1b15920 @tokens=[1 (weight: 1 grams, metric), text: something]

Again, it has the correct tokens, just need to pull them out correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.