From 0ce952239c7e3eec75d3d1047c64cd2c02a06501 Mon Sep 17 00:00:00 2001 From: MonalisaC Date: Thu, 9 Feb 2017 09:12:50 -0800 Subject: [PATCH 1/2] Create random_menu.rb --- random_menu.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 random_menu.rb diff --git a/random_menu.rb b/random_menu.rb new file mode 100644 index 0000000..2925f61 --- /dev/null +++ b/random_menu.rb @@ -0,0 +1,13 @@ +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", "muffins", "chips", "chicken", "noodles", "taco", "rice", "quinoa", "fruits"] + + +10.times do |n| +#puts "#{n + 1}. #{adjectives.shuffle[0]} #{cooking_styles.shuffle[0]} #{foods.shuffle[0]}" +#end +a = rand(0..9) +b = rand(0..9) +c = rand(0..9) +puts "#{n+1}. #{adjectives[a]} #{cooking_styles[b]} #{foods[c]}" +end From 24cf7f6cc0bc7a9b6f3d694580c827f8694886ac Mon Sep 17 00:00:00 2001 From: Monalisa Chatterjee Date: Tue, 6 Feb 2018 11:12:52 -0800 Subject: [PATCH 2/2] Random Menu Generator --- random_menu.rb | 116 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 9 deletions(-) diff --git a/random_menu.rb b/random_menu.rb index 2925f61..87c7c6c 100644 --- a/random_menu.rb +++ b/random_menu.rb @@ -1,13 +1,111 @@ -adjectives = ["hot", "cold", "rotten", "smelly", "soft", "creamy", "delicious", "yummy", "sour", "bitter"] +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", "muffins", "chips", "chicken", "noodles", "taco", "rice", "quinoa", "fruits"] +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 -10.times do |n| -#puts "#{n + 1}. #{adjectives.shuffle[0]} #{cooking_styles.shuffle[0]} #{foods.shuffle[0]}" -#end -a = rand(0..9) -b = rand(0..9) -c = rand(0..9) -puts "#{n+1}. #{adjectives[a]} #{cooking_styles[b]} #{foods[c]}" +# Based on option display menu type +if option == 0 + create_menu(adjectives, cooking_styles) +else + fixed_menu(adjectives, cooking_styles, foods) end