class Randomeal::Food

Attributes

directions[RW]
ingredients[RW]
option[RW]
title[RW]
url[RW]

Public Class Methods

new(option) click to toggle source
# File lib/randomeal/food.rb, line 5
def initialize(option)
    @option = option
    self.scrape_url
    @title = "#{self.scrape_title}"
    @directions = []
    @ingredients = []
    self.scrape_directions
    self.scrape_ingredients

end

Public Instance Methods

scrape_directions() click to toggle source
# File lib/randomeal/food.rb, line 43
def scrape_directions
    recipe = Nokogiri::HTML(open("#{@url}"))

    direction_list = recipe.css('.recipe-procedures-list.instructions')
    direction_list.each{|step| @directions << step.text.strip}

end
scrape_ingredients() click to toggle source
# File lib/randomeal/food.rb, line 29
def scrape_ingredients
    recipe = Nokogiri::HTML(open("#{@url}"))

    ingredient = recipe.css('.recipe-ingredients')
    ingredient.each{|i| @ingredients << i.text.strip}
end
scrape_title() click to toggle source
# File lib/randomeal/food.rb, line 36
def scrape_title
    recipe = Nokogiri::HTML(open("#{@url}"))

    title = recipe.css('.recipe-title').text.strip
    title
end
scrape_url() click to toggle source

scrapes each option to object

# File lib/randomeal/food.rb, line 18
def scrape_url        
        recipe_url = Nokogiri::HTML(open("http://seriouseats.com/tags/recipes/#{@option}"))
    
        recipe_links = []
        links = recipe_url.css('.module__link')
        links.each{|link| recipe_links << link['href']}
    
        @url = recipe_links.sample
        @url
end