Class: FindRecipe::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/find_recipe/recipe.rb

Direct Known Subclasses

SearchedRecipe, TrendingRecipe

Defined Under Namespace

Classes: SearchedRecipe, TrendingRecipe

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/find_recipe/recipe.rb', line 2

def description
  @description
end

#ingredientsObject

Returns the value of attribute ingredients.



2
3
4
# File 'lib/find_recipe/recipe.rb', line 2

def ingredients
  @ingredients
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/find_recipe/recipe.rb', line 2

def name
  @name
end

#stepsObject

Returns the value of attribute steps.



2
3
4
# File 'lib/find_recipe/recipe.rb', line 2

def steps
  @steps
end

#urlObject

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_dataObject



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_detailsObject



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_browserObject



40
41
42
# File 'lib/find_recipe/recipe.rb', line 40

def open_in_browser
  system("open", self.url)
end