Class: RecipeBook::CLI

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

Overview

CLI Controller

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  welcome
  start
end

#list_recipesObject



15
16
17
18
19
20
21
# File 'lib/recipe_book/cli.rb', line 15

def list_recipes
  puts "--------------------- Drink List ---------------------"
  puts ''
  RecipeBook::Recipe.all.each.with_index(1) do |r, i|
    puts "#{i}. #{r.name}"
  end
end

#show_recipe(recipe) ⇒ Object

> end of start method



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/recipe_book/cli.rb', line 56

def show_recipe(recipe)
  puts ''
  puts "--------------------- #{recipe.name.upcase} ---------------------"
  puts ""
  puts "#{recipe.description}"
  puts ""
  puts "  Ingredients"
  puts "---------------"
  puts "#{recipe.ingredients}"
  puts ""
  puts "  Instructions"
  puts "---------------"
  puts "#{recipe.instructions}"


end

#startObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/recipe_book/cli.rb', line 23

def start
  puts ''
  list_recipes

  input = nil
  while input != "exit"
    puts ''
    puts ''
    puts "What are you in the mood for?"
    puts ''
    puts "Enter the number of the drink recipe you want to see."
    puts ''
    input = gets.strip.to_i

    recipe = RecipeBook::Recipe.find(input.to_i)

    show_recipe(recipe)
    puts ''
    puts "Want to see a different recipe? Enter 'yes' or 'no'."
    puts ''
    input = gets.strip.downcase
    case input
      when "yes"
        start
      when 'no'
        puts ''
        puts "Cheers!"
        puts ''
        exit
      end
  end
end

#welcomeObject



10
11
12
13
# File 'lib/recipe_book/cli.rb', line 10

def welcome
  puts "----------- Classic Mixed Drink Recipe Book -----------"
  puts ''
end