class SeriousEats::CLI

Public Instance Methods

call() click to toggle source
# 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_recipes() click to toggle source
# 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_message() click to toggle source
# File lib/serious-eats/cli.rb, line 59
def goodbye_message
  puts ""
  puts "Thank you! Goodbye!".bold
  puts ""
end
invalid_message() click to toggle source
# File lib/serious-eats/cli.rb, line 53
def invalid_message
  puts ""
  puts "PLEASE ENTER A VALID RESPONSE.".colorize(:red).blink
  start
end
print_recipe(recipe) click to toggle source
start() click to toggle source
# 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