forked from Ada-C8/Random-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_menu_generator_JE.rb
More file actions
135 lines (104 loc) · 4.62 KB
/
random_menu_generator_JE.rb
File metadata and controls
135 lines (104 loc) · 4.62 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#USER INTRO PROMPT------------------------------------
introduction = <<YES
"Welcome to the Regional Randomized Menu Generator! To begin, enter:
\n(A) If you would like to generate a menu from our default menu items or,
\n(B) If you would like to enter your own menu item details."
YES
#OPTION A - DEFAULT MENU GENERATOR METHOD---------(BASELINE GENERATOR)---------
def default_menu_generator
#USER ENTRY VALIDATION METHOD (~!But doesn't account for floats)
def is_numeric?(obj)
obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) ==
nil ? false : true
end
#PROMPTS USER FOR PREFERRED TOTAL ITEMS ON MENU (user_total)
puts "You've selected our Default Menu Generator!"
puts "\nTo proceed, provide the total number of items you would like the generated menu to feature."
puts "NOTE: The number must be a positive integer. \n\nMenu Item Total?" #~!what's best way of writing the put statements?
user_total = gets.chomp
while !(is_numeric?(user_total))
puts "Remember, positive integers only! "
user_total = gets.chomp
end
menu_total = user_total.to_i
#DEFAULT ARRAYS FOR MENU ITEM COMBINATIONS
food_region = ["Indian", "Italian", "Mediterranean", "Mexican", "Morroccan", "Nepalese", "Seattle", "Szechuan", "Thai", "Umbrian"]
star_ingredient = ["Beef", "Chicken and Apple", "Eggplant", "Fennel Sausage", "Glazed Wild Salmon", "Grilled Tilapia", "Heirloom Tomato", "Pork", "Raspberry", "Shrimp"]
food_type = ["Curry", "Enchiladas", "Lasagna", "Pasta", "Pilaf", "Pizza", "Salad", "Sandwich", "Soup", "Stew"]
#LOOP PULLS 1 RANDOM ELEMENT FROM EACH DEFAULT ARRAY TO CREATE A MENU ITEM AND PUSHES IT INTO THE MENU ARRAY
menu = []
menu_total.times do |x|
menu.push("#{food_region.sample} #{star_ingredient.sample} #{food_type.sample}")
end
#LOOP PRINTS THE FINAL MENU OF RANDOMIZED MENU ITEMS
menu_total.times do |i|
menu_item = menu.sample
puts "#{i+1}" + ": " + menu_item
end
end
#OPTION B - USER'S CHOICE MENU GENERATOR METHOD---------------------------------
def users_choice_menu_generator
#USER ENTRY VALIDATION METHOD (~!But doesn't account for floats)
def is_numeric?(obj)
obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) ==
nil ? false : true
end
#PROMPTS USER FOR PREFERRED TOTAL ITEMS ON MENU (user_total)
puts "You've selected our User's Choice Menu Generator!"
puts "\nTo proceed, provide the total number of items you would like the generated menu to feature."
puts "NOTE: The number must be a positive integer. \n\nMenu Item Total?" #~!what's best way of writing the put statements?
user_total = gets.chomp
while !(is_numeric?(user_total))
puts "Remember, positive integers only! "
user_total = gets.chomp
end
menu_total = user_total.to_i
#USER CHOICE ENTRY INSTRUCTIONS
puts "\nTo generate a menu item, please enter #{menu_total} choices for each of the following categories:"
puts "(1) Region of a potential dish, \n(2) Starring main ingredient(s) of a dish, and \n(3) Dish type [e.g. pizza, pasta, salad, curry, etc.]"
#USER'S CHOICE ENTRY PROMPTS & ARRAYS FOR MENU ITEM COMBINATIONS
dish_region = []
star_ingredients = []
dish_type = []
menu_total.times do
puts "\nPlease enter a potential dish's regional cuisine below. (Examples: Italian, Morroccan, Thai, etc.)"
region_choice = gets.chomp.capitalize
dish_region.push(region_choice)
end
menu_total.times do
puts "\nPlease enter a starring main ingredient(s) of a dish below:"
ingredient_choice = gets.chomp.capitalize
star_ingredients.push(ingredient_choice)
end
menu_total.times do
puts "\nPlease enter a dish type below. (Examples include: pizza, pasta, salad, curry, etc.):"
dish_choice = gets.chomp.capitalize
dish_type.push(dish_choice)
end
#PULLS 1 RANDOM ELEMENT FROM EACH OF THE 3 ARRAYS AND PUSHES IT INTO THE MENU ARRAY
menu = []
menu_total.times do |x|
menu.push("#{dish_region.sample} #{star_ingredients.sample} #{dish_type.sample}")
end
menu_total.times do |i|
menu_item = menu.sample
puts "#{i+1}" + ": " + menu_item
end
end
#_______________________________________________________________________________
puts introduction
begin_option = gets.chomp.upcase
#------RUNNING OPTION A OR B------
#REPROMPT USER TO ENTER BEGIN OPTION IF begin_option IS NOT A OR B
while true
if begin_option == "A" || begin_option == "(A)"
default_menu_generator #RUNS THE DEFAULT MENU GENERATOR METHOD
Process.exit(0)
elsif begin_option == "B" || begin_option == "(B)"
users_choice_menu_generator #RUNS THE USER'S CHOICE MENU GENERATOR METHOD
Process.exit(0)
else
puts "Please enter A or B."
begin_option = gets.chomp.upcase
end
end