Class: FindRecipe::Recipe
- Inherits:
-
Object
- Object
- FindRecipe::Recipe
- Defined in:
- lib/find_recipe/recipe.rb
Direct Known Subclasses
Defined Under Namespace
Classes: SearchedRecipe, TrendingRecipe
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#name ⇒ Object
Returns the value of attribute name.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_additional_recipe_data ⇒ Object
- #get_details ⇒ Object
-
#initialize(recipe_hash) ⇒ Recipe
constructor
Passes in data from scraper when recipe is created.
- #open_in_browser ⇒ Object
Constructor Details
#initialize(recipe_hash) ⇒ Recipe
Passes in data from scraper when recipe is created
5 6 7 8 9 |
# File 'lib/find_recipe/recipe.rb', line 5 def initialize(recipe_hash) recipe_hash.each do |attribute, value| self.send(("#{attribute}="), value) end end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/find_recipe/recipe.rb', line 2 def description @description end |
#ingredients ⇒ Object
Returns the value of attribute ingredients.
2 3 4 |
# File 'lib/find_recipe/recipe.rb', line 2 def ingredients @ingredients end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/find_recipe/recipe.rb', line 2 def name @name end |
#steps ⇒ Object
Returns the value of attribute steps.
2 3 4 |
# File 'lib/find_recipe/recipe.rb', line 2 def steps @steps end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/find_recipe/recipe.rb', line 2 def url @url end |
Instance Method Details
#add_additional_recipe_data ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/find_recipe/recipe.rb', line 11 def add_additional_recipe_data additional_recipe_data = FindRecipe::Scraper.scrape_individual_recipe_data(self.url) additional_recipe_data.each do |attribute, value| self.send(("#{attribute}="), value) end self end |
#get_details ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/find_recipe/recipe.rb', line 21 def get_details puts "\n\n" puts "Details for #{@name}:" puts "\n\n" puts "Description:".green puts @description puts "\n\n" puts "Ingredients:".green @ingredients.each do |ingredient| puts ingredient end puts "\n\n" puts "Steps:".green @steps.each.with_index(1) do |step, step_number| puts "#{step_number}.".blue + " #{step}" end puts "\n\n" end |
#open_in_browser ⇒ Object
40 41 42 |
# File 'lib/find_recipe/recipe.rb', line 40 def open_in_browser system("open", self.url) end |