Class: SeattleCraftCoffee::Cli

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  greeting
  run_scraper
  list
  menu
  goodbye
end

#goodbyeObject



69
70
71
72
73
# File 'lib/seattle_craft_coffee/cli.rb', line 69

def goodbye
  puts ""
  puts "Goodbye..."
  puts ""
end

#greetingObject



11
12
13
# File 'lib/seattle_craft_coffee/cli.rb', line 11

def greeting
  puts "Welcome to Seattle's Top Craft Coffee.  Here are the top craft coffee brewers in Seattle:"
end

#invalid_choiceObject



59
60
61
62
# File 'lib/seattle_craft_coffee/cli.rb', line 59

def invalid_choice
  puts "Sorry that wasn't a valid choice"
  menu
end

#listObject



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

def list
  SeattleCraftCoffee::Brewers.all.each.with_index(1) do |brewer, index|
    puts ""
    puts "#{index}.  #{brewer.name}"
    puts "    --Located in #{brewer.neighborhood}"
  end
end


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
52
53
54
55
56
57
# File 'lib/seattle_craft_coffee/cli.rb', line 27

def menu
  puts ""
  puts "Which Craft Coffee brewer's description would you like to read? Enter the number or 'exit':"
  input = gets.strip
  if input.to_i.between?(1, 10)
    brewer = SeattleCraftCoffee::Brewers.all[input.to_i-1]
    puts ""
    puts "*** #{brewer.name} *** "
    puts ""
    puts "   #{brewer.description} --"
    puts ""
    puts "Would you like to read about another Seattle Craft Coffee brewer?"
    input = gets.strip.downcase
    if input == "yes" || input == "y"
      menu
    else
      sign_off
    end
  elsif input == "exit"
    puts ""
    puts "Are you sure you would like to exit? Yes/No:"
    input = gets.strip.downcase
    if input == "no" || input == "n"
      menu
    else
      sign_off
    end
  else
    invalid_choice
  end
end

#run_scraperObject



15
16
17
# File 'lib/seattle_craft_coffee/cli.rb', line 15

def run_scraper
  SeattleCraftCoffee::Scraper.scrape_brewers
end

#sign_offObject



64
65
66
67
# File 'lib/seattle_craft_coffee/cli.rb', line 64

def sign_off
  puts ""
  puts "Enjoy your craft coffee!  "
end