class CommandLineInterface
Constants
- BASE_CATEGORIES
- CATEGORY_BASE_URL
Public Instance Methods
call()
click to toggle source
# File lib/recipe-grater/cli.rb, line 8 def call puts "Welcome to Grater! \n\n" puts "Select from the following categories: \n\n" print_categories print_collections(input) puts "\n\n" puts "Select a collections: \n\n" print_recipes(input) print_full_recipe(input) end
create_recipe(chosen_recipe)
click to toggle source
# File lib/recipe-grater/cli.rb, line 57 def create_recipe(chosen_recipe) recipe = Grater.all[chosen_recipe] details = Scraper.recipe_scraper(recipe.recipe_url) recipe.recipe_details_creator(details) recipe end
create_recipe_list(input)
click to toggle source
# File lib/recipe-grater/cli.rb, line 41 def create_recipe_list(input) collection = CategoryCreator.all[input] url = collection.category_url recipe_list = Scraper.recipe_index_page_scraper(url) Grater.recipe_creator(recipe_list) end
input()
click to toggle source
# File lib/recipe-grater/cli.rb, line 19 def input input = gets.chomp.to_i - 1 input end
print_categories()
click to toggle source
# File lib/recipe-grater/cli.rb, line 24 def print_categories BASE_CATEGORIES.each_with_index do |category, index| puts "#{index + 1}. #{category}" end puts "\n" end
print_collections(input)
click to toggle source
# File lib/recipe-grater/cli.rb, line 31 def print_collections(input) category_list = Scraper.recipe_category_page_scraper(CATEGORY_BASE_URL + BASE_CATEGORIES[input]) CategoryCreator.category_creator(category_list) puts "\n" puts "#{BASE_CATEGORIES[input].capitalize} has the following collections: \n\n" CategoryCreator.all.each_with_index do |category, index| puts "#{index + 1}. #{category.category_name}" end end
print_full_recipe(chosen_recipe)
click to toggle source
# File lib/recipe-grater/cli.rb, line 76 def print_full_recipe(chosen_recipe) recipe = create_recipe(chosen_recipe) puts "\n#{recipe.recipe_name}" puts "------------------------------------------\n\n" puts "Ingredients" puts "-----------\n\n" recipe.ingredients.each {|i| puts "* #{i} \n"} puts "\n\n" puts "Steps" puts "-----\n\n" recipe.method.each_with_index {|step, index| puts "#{index + 1}. #{step} \n\n"} end
print_ingredients(chosen_recipe)
click to toggle source
# File lib/recipe-grater/cli.rb, line 64 def print_ingredients(chosen_recipe) recipe = create_recipe(chosen_recipe) puts "\n #{recipe.recipe_name} Ingredients: \n\n" recipe.ingredients.each {|i| puts "* #{i} \n"} end
print_method(chosen_recipe)
click to toggle source
# File lib/recipe-grater/cli.rb, line 70 def print_method(chosen_recipe) recipe = create_recipe(chosen_recipe) puts "\n #{recipe.recipe_name} Steps: \n\n" recipe.method.each_with_index {|step, index| puts "#{index + 1}. #{step} \n"} end
print_recipes(input)
click to toggle source
# File lib/recipe-grater/cli.rb, line 48 def print_recipes(input) create_recipe_list(input) puts "\n" Grater.all.each_with_index do |recipe, index| puts "#{index + 1}. #{recipe.recipe_name}" end puts "\n\n" end