Git Product home page Git Product logo

hangry's Introduction

Hangry

Parses microformatted recipe HTML into a plain-old-ruby Recipe object.

Currently supported microformats:

Pieces of Flair

  • Build Status
  • Code Climate

Installation

Add this line to your application's Gemfile:

gem 'hangry'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hangry

Usage

require 'open-uri'
recipe_url = "http://www.foodnetwork.com/recipes/rachael-ray/spinach-and-mushroom-stuffed-chicken-breasts-recipe/index.html"
recipe_html_string = open(recipe_url).read

require 'hangry'
recipe = Hangry.parse(recipe_html_string)
recipe.author         # "Rachel Ray"
recipe.cook_time      # 20
recipe.description    # nil
recipe.image_url      # "http://img.foodnetwork.com/FOOD/2008/08/13/av-rachael-ray.jpg"
recipe.ingredients    # ["4 boneless, skinless chicken breasts, 6 ounces", "Large plastic food storage bags or waxed paper", "1 package, 10 ounces, frozen chopped spinach", "2 tablespoons butter", "12 small mushroom caps, crimini or button", "2 cloves garlic, cracked", "1 small shallot, quartered", "Salt and freshly ground black pepper", "1 cup part skim ricotta cheese", "1/2 cup grated Parmigiano or Romano, a couple of handfuls", "1/2 teaspoon fresh grated or ground nutmeg", "Toothpicks", "2 tablespoons extra-virgin olive oil", "2 tablespoons butter", "2 tablespoons flour", "1/2 cup white wine", "1 cup chicken broth"]
recipe.instructions   # "Place breasts in the center of a plastic food storage..."
recipe.name           # "Spinach and Mushroom Stuffed Chicken Breasts"
recipe.prep_time      # 15
recipe.published_date # #<Date: 2013-02-06 >
recipe.total_time     # 35
recipe.yield          # "4 servings"
# etc..

Live demo

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

hangry's People

Contributors

iancanderson avatar johnnaegle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hangry's Issues

Support multi-step instructions and single-block ingredients

According to http://schema.org/Recipe definition, recipe instructions may be either a block of text or a list. Same thing when it comes to ingredients. However Hangry always returns an array of strings for ingredients and string for instructions, therefore it loses important piece of information.

Fortunately when it comes to instructions, the loss is easy to revert. Instructions are typically joined with "\n" and I can split this string to get original list. It doesn't seem right though, it's actually parsing the output of parser, I guess Hangry should do that.

When it comes to ingredients, it's much worse. For recipes which describe the ingredients as a block of text, this field will be usually blank. And modifying Hangry so that it returns one-item-long array doesn't seem right too.

In my opinion, Hangry's #instructions should return an array of strings if given recipe differentiate steps, and string otherwise. Similarly #ingredients should not be guaranteed to be an array. In Ruby it's not uncommon that class of some method's return value depends on situation.

I can implement it tomorrow, but it would be a breaking change, therefore I wanted to consult the interfaces before I start.

Alternatively, another methods #instructions_list, #ingredients_list, #instructions_text and #ingredients_text could be implemented. The "list" methods would return nil when only plain text is available. This approach does not introduce a breaking change, on the other hand provide 6 methods to access these two fields can be pretty confusing I think. Perhaps #instructions and #ingredients should be deprecated then.

Support for many Schema.org recipeInstructions elements

I was just using Hangry with a few pages like http://www.jocooks.com/healthy-eating/chicken-fajita-quesadillas/ and http://crockpotgourmet.net/2014/06/30/crockpot-buffalo-chicken-tater-tot-casserole/, and it Hangry is only pulling in the first element with the itemprop of recipeInstructions. The Schema docs say that recipeInstructions can either be an array (one on each step) or a single element (nodes inside it), but Hangry doesn't seem to support the former.

image_url not working

Hello! Love this gem. I ran through the example in the readme however the parsed recipe object does not have image_url method.

eg.
require 'open-uri'
require 'hangry'
recipe_url = "http://paleoleap.com/lobster-salad-taro-chips/"
recipe_html_string = open(recipe_url).read
recipe = Hangry.parse(recipe_html_string)
image_url = recipe.image_url

I'm on version 0.0.2
When I use the same recipe_url in the demo, the image_url is found. Is it on a different version?

Thanks.
John

AllRecipes parser fails for some recipes

We had this show up over the weekend. This URL

http://allrecipes.com/recipe/23600/worlds-best-lasagna/

fails in parse_instructions in lib/hangry/parsers/non_standard/all_recipes_parser.rb

Still maintained?

Is this gem still maintained? If not, I would be happy to take over ownership/maintenance (I am using it for a personal project). I have a branch (lukeasrodgers#4) that has updated all fixtures and fixed all parsers accordingly (except for http://www.cooking.com/ which is currently under maintenance).

cheers, and thanks for the gem

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.