class Allrecipes
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/allrecipes/main.rb, line 5 def initialize @agent = Mechanize.new end
Public Instance Methods
all(options={})
click to toggle source
# File lib/allrecipes/main.rb, line 9 def all(options={}) page = @agent.get $URL + "/recipes" + recipe_filters(options) PageParser.new(page, options).recipes end
course(course_type, options={})
click to toggle source
# File lib/allrecipes/main.rb, line 14 def course(course_type, options={}) recipe_search(course_type, options.merge({ url_type: "course" })) end
ingredient(name, options={})
click to toggle source
# File lib/allrecipes/main.rb, line 32 def ingredient(name, options={}) begin url = $URL + "/search/?wt=#{name}&page=#{options[:page]}&sb=#{ingredient_sort_parameter(options[:sort_by])}" page = @agent.get(url) options = options.merge({type: "ingredient"}) PageParser.new(page, options).recipes rescue Exception raise "Could not find recipes that include this ingredient" end end
page_url(url, keys=nil)
click to toggle source
# File lib/allrecipes/main.rb, line 51 def page_url(url, keys=nil) begin page = @agent.get(url) PageParser.new(page, { keys: keys }).recipes rescue Exception raise "This page does not contain recipes" end end
recipe_search(type, options)
click to toggle source
# File lib/allrecipes/main.rb, line 22 def recipe_search(type, options) begin url = recipes_url(type, options) page = @agent.get(url) PageParser.new(page, options).recipes rescue Exception raise "#{options[:url_type].capitalize} doesn't exist" end end
recipe_url(url, keys=nil)
click to toggle source
# File lib/allrecipes/main.rb, line 43 def recipe_url(url, keys=nil) begin RecipeParser.new(url, keys).recipe rescue Exception raise "This page does not contain a recipe" end end
region(region_type, options={})
click to toggle source
# File lib/allrecipes/main.rb, line 18 def region(region_type, options={}) recipe_search(region_type, options.merge({ url_type: "region" })) end