Created a menu program

menu.rb


def search(menus)
  puts "Please enter the material to search in hiragana"
  keyword = gets.chomp
  puts "-------------------------------"
  puts "Search material:#{keyword}"

  result_array = menus.select { |menu| menu[:title].include?(keyword) || menu[:ingredients].include?(keyword) }
  if !result_array.empty?
    show_results(result_array)
  else
    puts "Could not be found with the specified keyword\n\n"
  end
end


def show_results(results)
  puts "\n#{results.count}Found"
  results.each do |result|
    puts "-------------------------------"
    puts "menu: #{result[:title]}"
    puts "material: #{result[:ingredients]}"
  end
  puts "-------------------------------\n\n"
end




def feeling(menus)
  puts "This is how I feel now!\n\n"
  num = rand(0..menus.length - 1)
  results = menus[num]
  puts "     ▼ ▼ ▼     \n\n"


  results.each do |result|
    puts result[1]
  end 
  puts "\n\n"
end


menus = []

  #Japanese style
  menu = {title:"Meat and potatoes",ingredients:"Potatoes, onions, carrots, pork"}
  menus << menu
  menu = {title:"Buri radish",ingredients:"Buri, radish"}
  menus << menu
  menu = {title:"TKG",ingredients:"Egg rice, white soup stock, soy sauce"}
  menus << menu
  menu = {title:"Clam udon",ingredients:"Udon, green onions, clams"}
  menus << menu
  menu = {title:"Steamed clams and cabbage",ingredients:"Clams, green onions, cabbage"}
  menus << menu
  menu = {title:"Ginger grilled pork",ingredients:"Ginger, pork, onion"}
  menus << menu
  menu = {title:"Mackerel soup",ingredients:"Miso, white soup stock, mackerel can, green onion"}
  menus << menu
  menu = {title:"Kamadama Udon",ingredients:"Udon, egg, white soup stock"}
  menus << menu
  #Western style
  menu = {title:"curry",ingredients:"Onions, carrots, pork, potatoes, curry roux"}
  menus << menu
  menu = {title:"hamburger",ingredients:"Eggs, minced meat, onions"}
  menus << menu
  menu = {title:"Pot-au-feu",ingredients:"Onions, carrots, potatoes, black bean paste, consomme"}
  menus << menu
  menu = {title:"German potato",ingredients:"Potatoes, bacon, garlic"}
  menus << menu
  menu = {title:"Omelette rice",ingredients:"Eggs, chicken, tomatoes, onions"}
  menus << menu
  menu = {title:"gratin",ingredients:"Butter, flour, onions, macaroni, tori, cheese, milk"}
  menus << menu
  #Chinese
  menu = {title:"Surah Tanmen",ingredients:"Egg leek, ramen"}
  menus << menu
  menu = {title:"Fried rice",ingredients:"Pork, rice, eggs, green onions"}
  menus << menu
  menu = {title:"Twice-cooked meat",ingredients:"Pork, cabbage, peaman, gochujang, tenmenjan"}
  menus << menu
  menu = {title:"Soup fried rice",ingredients:"Pork, omelet rice, green onions, chicken gala"}
  menus << menu
  menu = {title:"Mapo tofu",ingredients:"Source of tofu, rice, green onions, sesame oil, and mabo"}
  menus << menu
  





bar = "-------------------------------"


while true do
  puts bar
  puts "\n Solve your "what to make and eat ..."! !!"
  puts "Please select a menu.\n\n"
  puts "0:Menu search by material"
  puts "1:Menu search by mood"
  puts "2:Display registration list"
  puts "3:I'm done.\n\n"
  puts bar

  case gets.to_i
  when 0
    puts "0:Menu search by material"
    search(menus)
  when 1
    puts "1:Menu search by mood"
    feeling(menus)
  when 2
    puts "2:Display registration list"
    puts menus
  when 3
    puts "3:I'm done."
    exit

  else
    puts"This is an invalid input."
    puts bar
  end
end

what ・ Menu support app

why ・ Created as one of the portfolios. ・ Because I often pondered what to make when cooking

issue -When 1 is selected and randomly output, one of Japanese, Western, and Chinese is selected and output from among them. ・ Describe the recipe creation procedure ・ I want to refactor the code in the recipe list

Recommended Posts

Created a menu program
To write a user-oriented program (1)
Ruby: I made a FizzBuzz program!
Precautions when writing a program: Part 3
I created a PDF in Java.
Created a selfish configuration file library
Create a Servlet program in Eclipse
[Ruby] A program that determines prime numbers
[Introduction to Java] How to write a Java program
A program that calculates factorials from 2 to 100