Class: Jukebox::CLI

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

Overview

CLI Controller

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  puts "Welcome to Jukebox!"
  list_concerts
  menu
  goodbye
end

#goodbyeObject



52
53
54
# File 'lib/jukebox/cli.rb', line 52

def goodbye
  puts "\nGoodbye! Thanks for using Jukebox! Check back soon for more concerts!"
end

#list_concertsObject



11
12
13
14
15
16
17
18
19
# File 'lib/jukebox/cli.rb', line 11

def list_concerts
  puts "Here is a list of artists coming to the Memphis area:\n\n"

  #calls the scrape_concerts method and prints each artists name in a list
  @concerts = Jukebox::Concert.scrape_concerts
  @concerts.each.with_index(1) do |concert, i|
    puts "#{i}. #{concert.artist_name}"
  end
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jukebox/cli.rb', line 21

def menu
  input = nil
  #As long as the user does not type "exit," they can keep viewing concert info
  while input != "exit"
    puts "\nPlease enter the number corresponding to the concert you\n"\
    "want to hear more about, type list to see the concerts again, or\n"\
    "type exit to leave Jukebox: "

    input = gets.strip.downcase
    # if the input is a number on the list, information about that concert
    # is printed
    if input.to_i > 0
      if(@concerts[input.to_i - 1] != nil)
        the_concert = @concerts[input.to_i - 1]
        puts "\nArtist name: #{the_concert.artist_name}"
        puts "Date: #{the_concert.date}"
        puts "Location: #{the_concert.location}"
        puts "Buy tickets: #{the_concert.url}"
      else #If their input is a number not on the list, an error message is printed
        puts "\nSorry, but Jukebox doesn't recognize that."
      end
    elsif input == "list" #If they type "list," the list of concerts is printed again
      list_concerts
    elsif input == "exit" #If they type "exit," the program ends
      break
    else
      puts "\nSorry, but Jukebox doesn't recognize that."
    end
  end
end