class CoffeeHunt::CLI

Public Class Methods

new() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 8
def initialize 
  @input = " "
end

Public Instance Methods

coffee_shop_operator() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 23
def coffee_shop_operator 
  list_coffee_shops
  make_a_selection
  while @input != "exit" && @input != "back"
    if valid?
      @coffee_shop= CoffeeShop.find_by_number(@input)
      puts @coffee_shop.details
      puts "Smells like a great brew!".colorize(:green).bold
    else
      puts "That was a bad coffee bean! Please try another?".colorize(:red).bold
    end
    make_a_selection
  end
end
farewell() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 76
def farewell
  puts " Thanks for searching for tasty beverages! Happy coffee hunting!"
end
list_coffee_shops() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 54
def list_coffee_shops
  CoffeeShop.all.each.with_index(1) do |coffee,index|
    # binding.pry
    puts "#{index}. #{coffee.name}"
  end
end
list_options() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 61
def list_options
  puts "Please select a coffee shop by number so you can receive more information!".colorize(:cyan)
  puts "If you wish to exit please type 'exit!'"
  puts "To select a different coffee shop please pick another number."
  puts "Type 'back' to return to the main menu"
  # puts "If you would like to return to the list of Coffee Shops then Enter 'back'."

end
make_a_selection() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 70
def make_a_selection
  list_options
  @input = gets.strip
  # start_hunt if @input == 'back'
end
pick_location() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 39
def pick_location 
  puts "So we can help you find a tasty caffeinated beverage, please enter your location."
  @input = gets.chomp 
  CoffeeShop.load_by_location(@input) unless @input == "exit"
  if @input != "exit" && CoffeeShop.all.length == 0 
    puts "Please try again"
    pick_location
  end 
end
start_hunt() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 12
def start_hunt
  puts "Welcome to Coffee Hunt CLI! ".colorize(:blue).bold
  # puts "Please start by entering your location so we can give you coffee shop suggestions!"
  # binding.pry
  while @input != "exit" 
    pick_location
    coffee_shop_operator unless @input == "exit"
  end 
  farewell
end
valid?() click to toggle source
# File lib/Coffee_Hunt/cli.rb, line 49
def valid?
  @input.to_i.between?(1,CoffeeShop.all.length)

end