-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookbook.rb
More file actions
70 lines (59 loc) · 1.33 KB
/
Copy pathcookbook.rb
File metadata and controls
70 lines (59 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Cookbook
attr_accessor :title
attr_accessor :recipes
def initialize(title)
@title = title
@recipes = []
end
def add_recipe(recipe)
@recipes << recipe
puts "Added a recipe to the collection: #{recipe.recipe_title}"
end
def delete_recipe(recipe)
@recipes.delete(recipe) {"not found"}
puts "Successfully deleted #{recipe.recipe_title}."
end
def recipe_titles
@recipes.each { |recipe|
puts recipe.recipe_title}
end
def recipe_ingredients
@recipes.each { |recipe|
print "These are the ingredients for #{recipe.recipe_title}: "
p recipe.ingredients }
end
def print_cookbook
puts "Your cookbook contains the following recipes:"
(1..@recipes.length).each do |x|
print "#{x}. "
@recipes[x-1].print_recipe
puts " "
end
end
def celebrity_plug
puts "This cookbook was approved by Gordon Ramsey!"
end
end
class Recipe
attr_accessor :recipe_title
attr_accessor :steps
attr_accessor :ingredients
def initialize(recipe_title, ingredients, steps)
@recipe_title = recipe_title
@ingredients = ingredients
@steps = steps
end
def print_recipe
puts "Title: #{@recipe_title}"
puts "Ingredients: "
(1..@ingredients.length).each do |x|
print "#{x}. "
puts @ingredients[x-1]
end
puts "Steps: "
(1..@steps.length).each do |x|
print "#{x}. "
puts @steps[x-1]
end
end
end