[Ruby] Created a menu program

2 minute read


def search(menus)
  puts "Please enter the hiragana characters to search"
  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 "I feel like this!\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 potato",ingredients:"potato, onion, carrot, butterflies"}
  menus << menu
  menu = {title: "yellow radish", ingredients: "yellow radish"}
  menus << menu
  menu = {title:"TKG",ingredients:"Eggs, rice, white soup, soy sauce"}
  menus << menu
  menu = {title: "Clam Udon", ingredients: "Udon, green onion, Clam"}
  menus << menu
  menu = {title: "Steamed clams and cabbage", ingredients: "Clams, green onions, cabbage"}
  menus << menu
  menu = {title: "Ginger grilled pork", ingredients: "Ginger, pig, onion"}
  menus << menu
  menu = {title:"Sara mackerel juice", ingredients:"Miso, white soup, mackerel, green onion"}
  menus << menu
  menu = {title: "Kamatama Udon", ingredients: "Udon, Egg, Shiro Dashi"}
  menus << menu
  #Western
  menu = {title:"Curry",ingredients:"Onions, carrots, pigs, potatoes, kareru"}
  menus << menu
  menu = {title:"hamburger",ingredients:"egg, ground, onion"}
  menus << menu
  menu = {title:"Potov",ingredients:"onion, carrot, potato, block bacon, konsome"}
  menus << menu
  menu = {title:"German potato",ingredients:"Potato, bacon, garlic"}
  menus << menu
  menu = {title:"Omelet rice",ingredients:"Egg, chicken, tomato, onion"}
  menus << menu
  menu = {title:"Gratin",ingredients:"Patter, Komugi, Onion, Mackerel, Tori, Chizu, Gyunyu"}
  menus << menu
  #Chinese
  menu = {title:"Thuratanmen",ingredients:"Eggs, Chinese chive, Ramen"}
  menus << menu
  menu = {title:"fried rice",ingredients:"butaniku, rice, egg, green onion"}
  menus << menu
  menu = {title: "Steamed meat", ingredients: "Butaniku, cabbage, peaman, kochujan, tenmenjan"}
  menus << menu
  menu = {title: "Soup fried rice",ingredients: "Butaniku, egg, rice, green onion, and chicken"}
  menus << menu
  menu = {title: "Marbo tofu", ingredients: "Tofu, rice, green onions, sesame oil, and Mabotonomoto"}
  menus << menu
  





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


while true do
  puts bar
  puts "\n Solve your "what to make..."! ! "
  puts "Please select the menu.\n\n"
  puts "0: Menu search from material"
  puts "1: Menu search by mood"
  puts "2: Display registration list"
  puts "3: Exit.\n\n"
  puts bar

  case gets.to_i
  when 0
    puts "0: Menu search from 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: Finish."
    exit

  else
    puts "Invalid input"
    puts bar
  end
end

what

・Menu support app

why

・Created as one of portfolios. ・Because I often thought about what to make when cooking

issue

・When selecting 1 and randomly outputting, select either Japanese, Western or Chinese and output from that. ・Enter the recipe creation procedure ・I want to refactor the code in the recipe list

Tags:

Updated: