forked from Ada-C9/Random-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_menu.rb
111 lines (98 loc) · 3.74 KB
/
random_menu.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
require 'colorize'
# Display name
puts "
*************************
RANDOM MENU GENERATOR
*************************"
# Empty string
puts ""
# Welcome message
puts "*Welcome! This is today's Menu.*"
wish = "
____ __
/ ) / | ,
---/__ /-----__----__-------/__|------__------__----__--_/_------_/_-
/ ) / ) / ) / | / ) / ) /___) / / /
_/____/___(___/_/___/_____/____|___/___/___/___/_(___ _(_ __/___(_ __
/ /
/ / ".colorize(:light_blue).on_green.underline
# Display ascii text
puts wish
# Array of adjectives and styles
adjectives = ["Hot", "Cold", "Rotten", "Smelly", "Soft", "Creamy", "Delicious", "Yummy", "Sour", "Bitter"]
cooking_styles = ["panfried", "grilled", "deepfried", "baked", "sauted", "stirfried", "seasoned", "shallowed", "boiled", "roasted"]
foods = ["potato", "salad", "egg", "noodles", "rice", "omlette", "chicken", "lamb", "beans", "brownrice"]
# Method to create menu provided by user items
def create_menu(adjectives, cooking_styles)
# Prompt user to enter upto 10 items
puts "You can add upto 10 food items to generate your own menu. So how many items you want to add."
count = gets.chomp
# Count should match regex for digits and it should be any number between 1 to 10
until count =~ /(?=.*[0-9])/ && count.to_i <= 10 && count.to_i > 0
# Display warning message and prompt user again.
puts "Invalid Entry!".red.on_light_blue.blink
puts "Enter a number between 1 to 10. How many items you want to add?"
count = gets.chomp
end
# Create an array
user_items = []
# Ask favourite items from the user
count.to_i.times do |index|
puts "Please enter your favourite food items.Example: rice, salad, taco etc."
food_items = gets.chomp.downcase
# Until food items match regex and it doesn't include unique items display warning message and prompt user to enter again
until food_items =~ /^[a-zA-Z\s]+$/ && !user_items.include?(food_items)
if user_items.include?(food_items)
puts "Item already exists: #{user_items.inspect}!"
else
puts "Invalid Entry!".red.on_light_blue.blink
end
puts "Please enter your favourite food items.Example: rice, salad, taco etc."
food_items = gets.chomp.downcase
end
# Push food items in an array
user_items << food_items
end
create_menu = []
# Return an array of shuffled objects
adj = adjectives.shuffle
styles = cooking_styles.shuffle
items = user_items.shuffle
# Creates a list of menu items
user_items.length.times do |index|
create_menu << "#{index + 1}. #{adj[index]} #{styles[index]} #{items[index]}".blue
end
# Display menu
puts create_menu
puts ""
puts ""
end
def fixed_menu(adjectives, cooking_styles, foods)
# Create an array
fixed_menu = []
adj = adjectives.shuffle
styles = cooking_styles.shuffle
items = foods.shuffle
# Creates a list of menu items
foods.length.times do |index|
fixed_menu << "#{index + 1}. #{adj[index]} #{styles[index]} #{items[index]}".blue
end
# Display menu
puts fixed_menu
puts ""
puts ""
end
puts "Do you want to go for fixed menu or create your own. Enter 0 for create menu or 1 to fixed menu."
option = gets.chomp.to_i
# Until user enter either 0 or 1, display warning and prompt the user
until option == 0 || option == 1
puts "Invalid Entry!".red.on_light_blue.blink
puts "Do you want to go for fixed menu or create your own. Enter 0 for fixed menu or 1 to create menu."
option = gets.chomp.to_i
end
# Based on option display menu type
if option == 0
create_menu(adjectives, cooking_styles)
else
fixed_menu(adjectives, cooking_styles, foods)
end