class EverythingButTheKitchenSink::CLI
Public Instance Methods
call()
click to toggle source
call will be used to run function (will call methods in order of how they should execute)
# File lib/recipe_cli/cli.rb, line 8 def call shouldContinue = true listEmpty = false welcome_message enter_ingredients while !listEmpty && shouldContinue listEmpty = display_recipe_list if !listEmpty recipe = user_recipe_choice display_recipe_time_and_link(recipe) shouldContinue = other_options end end end
display_recipe_list()
click to toggle source
will print out numbered recipe list
# File lib/recipe_cli/cli.rb, line 38 def display_recipe_list if EverythingButTheKitchenSink::Recipe.all.count == 0 return true else EverythingButTheKitchenSink::Recipe.all.each_with_index do |recipe, index| puts (index + 1).to_s + "." + recipe.title end return false end end
display_recipe_time_and_link(recipe)
click to toggle source
will print recipe info (time and link)
# File lib/recipe_cli/cli.rb, line 72 def display_recipe_time_and_link(recipe) puts "\nThis meal can be ready in " + recipe.time.to_s + " minutes.\nFor detailed instructions go to: " + recipe.url end
enter_ingredients()
click to toggle source
will prompt/gets ingredients and send to API class
# File lib/recipe_cli/cli.rb, line 29 def enter_ingredients puts "\nPlease input your ingredients below. Separate each ingredient with a comma.\n" ingredients = gets.strip recipes = EverythingButTheKitchenSink::SpoonacularApi.get_recipes(ingredients) EverythingButTheKitchenSink::TransformData.get_id_and_title(recipes) end
other_options()
click to toggle source
prompt user for other options; will take in yes/no and either loop through or exit function and call leave method
# File lib/recipe_cli/cli.rb, line 77 def other_options puts "\nWould you like to see another recipe?\nPlease enter 'Yes' or 'No':" input = "" while input input = gets.strip.upcase case input when "YES" return true when "NO" puts "\nEnjoy your meal!" return false else puts "\nPlease enter 'Yes' or 'No'." end end end
user_recipe_choice()
click to toggle source
will prompt/gets recipe choice and will send to api. will call Recipe class object to add info
# File lib/recipe_cli/cli.rb, line 50 def user_recipe_choice puts "\nWhich recipe would you like to see?\nPlease input the recipe number:\n" input = gets.strip if valid_recipe_choice(input) recipe_index = (input.to_i - 1) attributes = EverythingButTheKitchenSink::SpoonacularApi.recipe_info(recipe_index) recipe_object = EverythingButTheKitchenSink::Recipe.all[recipe_index] EverythingButTheKitchenSink::TransformData.get_time_and_url(attributes, recipe_object) recipe_object else user_recipe_choice end end
valid_recipe_choice(input)
click to toggle source
checks if recipe choice number is valid choice
# File lib/recipe_cli/cli.rb, line 67 def valid_recipe_choice(input) input.to_i.between?(1,10) end
welcome_message()
click to toggle source
will print welcome message
# File lib/recipe_cli/cli.rb, line 24 def welcome_message puts "Welcome to Everything but the Kitchen Sink!" end