Class: CoffeeHunt::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



8
9
10
# File 'lib/Coffee_Hunt/cli.rb', line 8

def initialize 
  @input = " "
end

Instance Method Details

#coffee_shop_operatorObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

#farewellObject



76
77
78
# File 'lib/Coffee_Hunt/cli.rb', line 76

def farewell
  puts " Thanks for searching for tasty beverages! Happy coffee hunting!"
end

#list_coffee_shopsObject



54
55
56
57
58
59
# 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_optionsObject



61
62
63
64
65
66
67
68
# 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_selectionObject



70
71
72
73
74
# File 'lib/Coffee_Hunt/cli.rb', line 70

def make_a_selection
  list_options
  @input = gets.strip
  # start_hunt if @input == 'back'
end

#pick_locationObject



39
40
41
42
43
44
45
46
47
# 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_huntObject



12
13
14
15
16
17
18
19
20
21
# 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?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/Coffee_Hunt/cli.rb', line 49

def valid?
  @input.to_i.between?(1,CoffeeShop.all.length)

end