Class: DailyRecipe::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/daily_recipe/cli.rb

Overview

our CLI controller

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
# File 'lib/daily_recipe/cli.rb', line 5

def call
  puts "Here are today's Daily Recipes"
  list_recipes
  menu
end

#goodbyeObject



47
48
49
# File 'lib/daily_recipe/cli.rb', line 47

def goodbye
  puts "Please visit again for more amazing recipes!"
end

#list_recipesObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/daily_recipe/cli.rb', line 11

def list_recipes
  #will get recipes
  @recipes = DailyRecipe::Recipe.today
  rows = [] # terminal-table formatting
  rows << ["Number", "Recipe Name", "Rating", "Cooking Time"]
  @recipes.each.with_index(1) do |recipe, i|  #There is a Recipe class with a #today method for today's recipes
    rows << [i, recipe.name, "#{recipe.rating} / 5", recipe.cook_time]
  end
  table = Terminal::Table.new :rows => rows #AWESOME!
  puts table
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/daily_recipe/cli.rb', line 23

def menu

  input = nil
  while input != "exit"
    puts "Enter the number of the recipe you would like to explore."
    puts "Enter list to see the full list of recipes."
    puts "Type exit to exit"
    input = gets.strip.downcase

    if input.to_i > 0 and input.to_i <= @recipes.count
      the_recipe = @recipes[input.to_i-1]
      puts "#{the_recipe.name} -       #{the_recipe.rating} -        #{the_recipe.cook_time}"
      DailyRecipe::Recipe.scrape_full_recipe(the_recipe)
    elsif input == "list"
      list_recipes
    elsif input == "exit"
      goodbye
    else
      puts "Not sure what you are asking for, type list or exit."
    end

  end
end