Class: TodaysTopDesserts::CLI

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

Instance Method Summary collapse

Instance Method Details

#add_attributes_to_recipesObject



19
20
21
22
23
24
25
# File 'lib/todays_top_desserts/cli.rb', line 19

def add_attributes_to_recipes
  #scrapes additional attributes from the individual recipe's page and adds the attributes to the Recipe
  TodaysTopDesserts::Recipe.today.each do |recipe|
    attributes = TodaysTopDesserts::Scraper.scrape_recipe(recipe.url)
    recipe.add_recipe_attributes(attributes)
  end
end

#callObject



3
4
5
6
7
8
9
# File 'lib/todays_top_desserts/cli.rb', line 3

def call
  create_recipes
  add_attributes_to_recipes
  list_desserts
  menu
  goodbye
end

#create_recipesObject



11
12
13
14
15
16
17
# File 'lib/todays_top_desserts/cli.rb', line 11

def create_recipes
  #scrapes name and url of recipes
  recipes_array = TodaysTopDesserts::Scraper.scrape_desserts

  #creates recipes using the array from the scrape_desserts method
  TodaysTopDesserts::Recipe.create_from_collection(recipes_array)
end

#goodbyeObject



81
82
83
84
# File 'lib/todays_top_desserts/cli.rb', line 81

def goodbye
  puts ""
  puts "Hope you bake something delicious today! See you later!"
end

#list_dessertsObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/todays_top_desserts/cli.rb', line 27

def list_desserts
  puts ""
  puts "Here are today's most made desserts:"
  puts ""
  @recipes = TodaysTopDesserts::Recipe.today
  @recipes.each.with_index(1) do |recipe, i|
    puts "#{i}.".colorize(:light_black) + " #{recipe.name}"
  end

end


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/todays_top_desserts/cli.rb', line 38

def menu
  input = nil
  while input != "exit"
    puts ""
    puts "Please enter either the number of the recipe you'd like to view, 'list' to see the list of recipes again, or 'exit' to close the program:"
    input = gets.strip.downcase
    if input.to_i > 0 && input.to_i < 11
      @the_recipe = @recipes[input.to_i-1]
      puts_recipe
    elsif input == "list"
      list_desserts
    elsif input == "exit"
    else
      puts ""
      puts "Not sure what you meant by that."
    end
  end
end

#puts_recipeObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/todays_top_desserts/cli.rb', line 57

def puts_recipe
  puts ""
  puts "#{@the_recipe.name}".colorize(:cyan).bold
  puts "by #{@the_recipe.author}" if @the_recipe.author != ""
  puts ""
  puts "#{@the_recipe.description}".italic if @the_recipe.description != ""
  puts ""
  puts "Ready in: ".colorize(:light_black) + "#{@the_recipe.ready_time}" if @the_recipe.ready_time != ""
  puts "Prep time: ".colorize(:light_black) + "#{@the_recipe.prep_time}" if @the_recipe.prep_time != ""
  puts "Cook time: ".colorize(:light_black) + "#{@the_recipe.cook_time}" if @the_recipe.cook_time != ""
  puts "Serving size: ".colorize(:light_black) + "#{@the_recipe.serving_size}" if @the_recipe.serving_size != ""
  puts "Calorie count: ".colorize(:light_black) + "#{@the_recipe.calorie_count}" if @the_recipe.calorie_count != ""
  puts ""
  puts "INGREDIENTS:".colorize(:light_red).underline
  @the_recipe.ingredients.each do |ingredient|
    puts "#{ingredient}"
  end
  puts ""
  puts "INSTRUCTIONS:".colorize(:light_red).underline
  @the_recipe.instructions.each.with_index(1) do |instruction, i|
    puts "#{i}.".colorize(:light_black) + " #{instruction}"
  end
end