Class: CoffeeRoasters::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  puts ""
  puts "<<<<<<< Welcome to The 21 Best Coffee Roasters cli gem! >>>>>>>"
  CoffeeRoasters::Scraper.new.scrape_roasters
  list_roasters(1)
  menu
end

#goodbyeObject



78
79
80
81
# File 'lib/coffee_roasters/cli.rb', line 78

def goodbye
  "Thanks for visiting! Enjoy your coffee!"
  exit
end

#list_roasters(from_number) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/coffee_roasters/cli.rb', line 41

def list_roasters(from_number)
  @roaster = CoffeeRoasters::Roaster.all
  if from_number == 16
    puts ""
    puts "----------- Coffee Roasters #{from_number} - #{from_number+5} -----------"
    puts ""
    @roaster[from_number-1, 6].each.with_index(from_number) do |roaster, index|
      puts "#{index}. #{roaster.name} - #{roaster.location}"
      puts "#{roaster.bean}"
      puts ""
    end
  else
    puts ""
    puts "----------- Coffee Roasters #{from_number} - #{from_number+4} -----------"
    puts ""
    @roaster[from_number-1, 5].each.with_index(from_number) do |roaster, index|
      puts "#{index}. #{roaster.name} - #{roaster.location}"
      puts "#{roaster.bean}"
      puts ""
    end
  end
end


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coffee_roasters/cli.rb', line 11

def menu
  input = nil
  while input != 'exit'
    puts "==================================================="
    puts "Enter the number of the coffee roaster you'd like more info on:"
    puts "Or type 'A', 'B', 'C', or 'D' for the list - A: 1-5, B: 6-10, C: 11-15, D: 16-21"
    puts "Or type 'exit'."

    input = gets.strip.downcase

    if input.to_i.between?(1, 21)
      roaster_detail(input.to_i-1)
    elsif input == "a"
      list_roasters(1)
    elsif input == "b"
      list_roasters(6)
    elsif input == "c"
      list_roasters(11)
    elsif input == "d"
      list_roasters(16)
    elsif input == "exit"
      goodbye
    else
      puts "invalid input."
    end

  end
end

#roaster_detail(num) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/coffee_roasters/cli.rb', line 64

def roaster_detail(num)
  @roaster = CoffeeRoasters::Roaster.all
  the_roaster = @roaster[num]
  puts "----------- #{num+1}: #{the_roaster.name} -----------"
  puts ""
  puts "#{the_roaster.name} - #{the_roaster.location}"
  puts "#{the_roaster.bean}"
  puts ""
  puts "#{the_roaster.details}"
  puts ""

  menu
end