-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookbook.rb
113 lines (94 loc) · 2.2 KB
/
cookbook.rb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class Cookbook
attr_accessor :title
attr_reader :recipes
def initialize(title)
@title = title
@recipes = []
end
def add_recipe(recipe)
@recipes << recipe.title
@recipes << recipe.ingredients
@recipes << recipe.steps
# puts "Added a recipe to the collection: #{recipe.title}"
end
def recipe_titles
puts "Printing all of the recipe names:"
for i in [email protected]
if i % 3 == 0
puts @recipes[i]
end
end
end
def recipe_ingredients
puts "Printing ingredients for all recipes:"
for i in [email protected]
if i % 3 == 1
puts "These are the ingredients for #{@recipes[i-1]}: #{@recipes[i]}."
end
end
end
def submit_recipe
puts "Would you like to submit a recipe? (Yes/No)"
sel = gets.capitalize.chomp
if sel == "Yes"
puts "Title?"
ttl = gets.chomp
puts "Ingredients (separated by commas)?"
ing = gets.chomp
puts "Steps (separated by commas)?"
stp = gets.chomp
@recipes << ttl
@recipes << ing.split(", ")
@recipes << stp.split(", ")
elsif sel == "No"
puts "Alrighty then."
else
puts "Incorrect input."
end
end
def print_cookbook
for i in [email protected]
y = 0
if i % 3 == 0
puts "Recipe Title: #{@recipes[i]}"
puts "Ingredients: #{@recipes[i+1].join(", ")}"
puts "Steps: "
@recipes[i+2].each do |x|
y += 1
puts "#{y}. " + x
end
puts " "
end
end
end
def search_ingredients
sel = []
puts "How many ingredients? (integer)"
num = gets.to_i
for i in 1..num
puts "Ingredient: (one at a time)"
sel << gets.chomp
end
for i in [email protected]
if i % 3 == 1
if @recipes[i].sort == sel.sort
puts "Found ingredients!"
puts "Ingredients contained in recipe: #{@recipes[i-1]}"
end
end
end
end
end
class Recipe
attr_accessor :title, :ingredients, :steps
def initialize(title, ingredients, steps)
@title = title
@ingredients = ingredients
@steps = steps
end
def print_recipe
puts "Recipe Name: #{self.title}"
puts "Ingredients: #{self.ingredients.join(", ")}"
puts "Steps: #{self.steps.join(", ")}"
end
end