Class: Randomeal::Food

Inherits:
Object
  • Object
show all
Defined in:
lib/randomeal/food.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option) ⇒ Food

Returns a new instance of Food.



5
6
7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#directionsObject

Returns the value of attribute directions.



3
4
5
# File 'lib/randomeal/food.rb', line 3

def directions
  @directions
end

#ingredientsObject

Returns the value of attribute ingredients.



3
4
5
# File 'lib/randomeal/food.rb', line 3

def ingredients
  @ingredients
end

#optionObject

Returns the value of attribute option.



3
4
5
# File 'lib/randomeal/food.rb', line 3

def option
  @option
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/randomeal/food.rb', line 3

def title
  @title
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/randomeal/food.rb', line 3

def url
  @url
end

Instance Method Details

#scrape_directionsObject



43
44
45
46
47
48
49
# 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_ingredientsObject



29
30
31
32
33
34
# 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_titleObject



36
37
38
39
40
41
# 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_urlObject

scrapes each option to object



18
19
20
21
22
23
24
25
26
27
# 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