epilicious 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 723c2ea5bb75df26cbb920aed70d8a08fbaccf8f
4
+ data.tar.gz: 79e5113bca5182bcabfa67ed0f8cb5067273d6e4
5
+ SHA512:
6
+ metadata.gz: b1d27433706f09943bb17847752a48d03ecd1897605df02e3c27e8db804fd29111357b64adf5ef6a6bdfe336c0615a1e27c9c711c96851d88c0bfd50e70c6d39
7
+ data.tar.gz: 1341ad316e84a9c4700a360130d6564fd55d15645613a5cdede0bd2aa4554f71c399303b432841a1c3ead90007a2956ccc023edbadf94671194e4c604b2c0577
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in epilicious.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yeehaa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Epilicious
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'epilicious'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install epilicious
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:default) do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'epilicious/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "epilicious"
8
+ spec.version = Epilicious::VERSION
9
+ spec.authors = ["Jan Hein Hoogstad"]
10
+ spec.email = ["yeehaa@codingthehumanities.com"]
11
+ spec.description = %q{a gem to parse recipes from epicurious}
12
+ spec.summary = %q{a gem to parse recipes from epicurious}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "mocha"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,59 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ require_relative './parser'
6
+ require_relative './recipe'
7
+
8
+ module Epilicious
9
+ class Fetcher
10
+ attr_reader :recipes
11
+
12
+ def initialize
13
+ @recipes ||= []
14
+ @base_url = "http://www.epicurious.com"
15
+ end
16
+
17
+ def fetch_recipes(index_url = default_index_url)
18
+ recipes_page = fetch_page(index_url)
19
+ recipes_urls = parser.parse_recipes_page(recipes_page)
20
+ recipes = recipes_urls.map do |url|
21
+ fetch_recipe(url)
22
+ end
23
+ recipes
24
+ end
25
+
26
+ def fetch_recipe(url = default_recipe_url)
27
+ recipe_page = fetch_page(url)
28
+ recipe = parser.parse_recipe_page(recipe_page)
29
+ Recipe.new(recipe)
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_page(url)
35
+ Nokogiri::HTML(open(@base_url + url))
36
+ end
37
+
38
+
39
+ def default_index_url
40
+ "/articlesguides/bestof/toprecipes/bestburgerrecipes"
41
+ end
42
+
43
+ def default_recipe_url
44
+ "/articlesguides/bestof/toprecipes/bestburgerrecipes/recipes/food/views/Grilled-Turkey-Burgers-with-Cheddar-and-Smoky-Aioli-354289"
45
+ end
46
+
47
+ def parser
48
+ @parser ||= Parser.new
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+ class Recipe
56
+ def initialize(args)
57
+ @name = args[:name]
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ module Epilicious
2
+ class Parser
3
+
4
+ def parse_recipes_page(page)
5
+ page.css('#artInner .recipe_result_right a').map {|link| link ['href'] }
6
+ end
7
+
8
+ def parse_recipe_page(page)
9
+ recipe = {}
10
+ recipe[:name] = name(page)
11
+ recipe[:servings] = servings(page)
12
+ recipe[:ingredients] = ingredients(page)
13
+ recipe[:instructions] = instructions(page)
14
+ recipe
15
+ end
16
+
17
+ private
18
+
19
+ def name(page)
20
+ page.css("div#headline h1").text
21
+ end
22
+
23
+ def servings(page)
24
+ page.css("div#recipe_summary p span").first.text
25
+ end
26
+
27
+ def ingredients(page)
28
+ ingredients_list = page.css("ul.ingredientsList li")
29
+ ingredients_list.map {|li| li.text}
30
+ end
31
+
32
+ def instructions(page)
33
+ preparation = page.css("div#preparation.instructions p")
34
+ preparation.map {|i| i.text}
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module Epilicious
2
+
3
+ class Recipe
4
+ attr_reader :name, :servings, :ingredients, :instructions
5
+
6
+ def initialize(args)
7
+ @name = args[:name]
8
+ @servings = args[:servings]
9
+ @ingredients = args[:ingredients]
10
+ @instructions = args[:instructions]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Epilicious
2
+ VERSION = "0.1.0"
3
+ end
data/lib/epilicious.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "epilicious/version"
2
+ require "epilicious/fetcher"
3
+
4
+ module Epilicious
5
+ def self.recipes
6
+ Fetcher.new.fetch_recipes
7
+ end
8
+ end