Class: EverythingButTheKitchenSink::CLI
- Inherits:
-
Object
- Object
- EverythingButTheKitchenSink::CLI
- Defined in:
- lib/recipe_cli/cli.rb
Instance Method Summary collapse
-
#call ⇒ Object
call will be used to run function (will call methods in order of how they should execute).
-
#display_recipe_list ⇒ Object
will print out numbered recipe list.
-
#display_recipe_time_and_link(recipe) ⇒ Object
will print recipe info (time and link).
-
#enter_ingredients ⇒ Object
will prompt/gets ingredients and send to API class.
-
#other_options ⇒ Object
prompt user for other options; will take in yes/no and either loop through or exit function and call leave method.
-
#user_recipe_choice ⇒ Object
will prompt/gets recipe choice and will send to api.
-
#valid_recipe_choice(input) ⇒ Object
checks if recipe choice number is valid choice.
-
#welcome_message ⇒ Object
will print welcome message.
Instance Method Details
#call ⇒ Object
call will be used to run function (will call methods in order of how they should execute)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/recipe_cli/cli.rb', line 8 def call shouldContinue = true listEmpty = false enter_ingredients while !listEmpty && shouldContinue listEmpty = display_recipe_list if !listEmpty recipe = user_recipe_choice display_recipe_time_and_link(recipe) shouldContinue = end end end |
#display_recipe_list ⇒ Object
will print out numbered recipe list
38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
will print recipe info (time and link)
72 73 74 |
# 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 ⇒ Object
will prompt/gets ingredients and send to API class
29 30 31 32 33 34 35 |
# 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 ⇒ Object
prompt user for other options; will take in yes/no and either loop through or exit function and call leave method
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/recipe_cli/cli.rb', line 77 def 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 ⇒ Object
will prompt/gets recipe choice and will send to api. will call Recipe class object to add info
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
checks if recipe choice number is valid choice
67 68 69 |
# File 'lib/recipe_cli/cli.rb', line 67 def valid_recipe_choice(input) input.to_i.between?(1,10) end |
#welcome_message ⇒ Object
will print welcome message
24 25 26 |
# File 'lib/recipe_cli/cli.rb', line 24 def puts "Welcome to Everything but the Kitchen Sink!" end |