Class: SeriousEats::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/serious-eats/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
10
11
# File 'lib/serious-eats/cli.rb', line 3

def call
  puts ""
  puts "Hello there! Welcome to the Serious Eats Recipes!".colorize(:green).bold

  @scraper = SeriousEats::Scraper.new
  @scraper.fetch_recipes

  start
end

#display_recipesObject



65
66
67
68
69
# File 'lib/serious-eats/cli.rb', line 65

def display_recipes
  SeriousEats::Recipe.all.each_with_index do |recipe, index|
    puts "#{index + 1}. #{recipe.name}"
  end
end

#goodbye_messageObject



59
60
61
62
63
# File 'lib/serious-eats/cli.rb', line 59

def goodbye_message
  puts ""
  puts "Thank you! Goodbye!".bold
  puts ""
end

#invalid_messageObject



53
54
55
56
57
# File 'lib/serious-eats/cli.rb', line 53

def invalid_message
  puts ""
  puts "PLEASE ENTER A VALID RESPONSE.".colorize(:red).blink
  start
end


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/serious-eats/cli.rb', line 71

def print_recipe(recipe)
  puts ""
  puts "#{recipe.name.upcase} - #{recipe.category.upcase}".colorize(:green).bold

  puts ""
  puts "Description:".bold
  puts recipe.description.join("\n\n")

  puts ""
  puts "Portion:".bold
  puts "#{recipe.portion}"
  puts ""
  puts "Active Cooking Time:".bold
  puts "#{recipe.active_time}"
  puts ""
  puts "Total Time:".bold
  puts "#{recipe.total_time}"
  puts ""

  if recipe.rating == 0
    puts "Rating: N/A".bold
  else
    puts "Rating out of 5:".bold
    puts "#{recipe.rating}"
  end

  puts ""
  puts "Ingredients:".bold
  recipe.ingredients.each do |ingredient|
    puts "#{ingredient}"
  end

  puts ""
  puts "Directions:".bold
  recipe.directions.each_with_index do |direction, index|
    puts "#{index + 1}. #{direction}"
  end

  puts ""
  puts "Website:".bold
  puts "#{recipe.url}"
end

#startObject



13
14
15
16
17
18
19
20
21
22
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
# File 'lib/serious-eats/cli.rb', line 13

def start
  puts ""
  puts "Please choose a number for the recipe you would like to view: 1-24.".bold
  puts ""

  display_recipes
  puts ""

  input = gets.strip.to_i

  if input >= 1 && input <= Recipe.all.count
    recipe = SeriousEats::Recipe.find(input)

    if !recipe.has_data?
      @scraper.fetch_recipe_data(recipe)
    end

    print_recipe(recipe)

    puts ""
    puts "Would you like to see another recipe? Please enter Y or N.".bold
    puts ""

    input = gets.strip.downcase

    if input == "y"
      puts ""
      start
    elsif input == "n"
      goodbye_message
    else
      invalid_message
    end

  else
    invalid_message
  end

end