class MusicExplorer::CLI

Public Instance Methods

artist_options(artist) click to toggle source
# File lib/music_explorer/cli.rb, line 48
def artist_options(artist)
  while true
    puts
    puts "Please select an option (1-4)"
    puts "1. Display #{artist.name}'s top tracks"
    puts "2. Display #{artist.name}'s genres"
    puts "3. Display albums by #{artist.name}"
    puts "4. Display artists related to #{artist.name}"
    puts "5. Go back to main menu"
    puts
    case get_numeric_input
      when 1
        display_top_tracks(artist)
      when 2
        display_genres(artist)
      when 3
        display_albums(artist)
      when 4
        display_related_artists(artist)
      when 5
        program_options
    end
  end
end
call() click to toggle source
# File lib/music_explorer/cli.rb, line 4
def call
  #Welcome message, initially called by the executable program
  puts "Welcome to the Music Explorer!"
  program_options
end
display_albums(artist) click to toggle source
# File lib/music_explorer/cli.rb, line 97
def display_albums(artist)
  if artist.albums
    puts
    puts "#{artist.name}'s releases include the following albums (up to 20):"
    print_numbered_list(artist.albums.uniq)
    puts
  else
    puts
    puts "Albums not available for #{artist.name}"
    puts
  end
end
display_artist(artist) click to toggle source
# File lib/music_explorer/cli.rb, line 42
def display_artist(artist)
  puts
  puts "Your search matched #{artist.name}"
  puts
end
display_genres(artist) click to toggle source
# File lib/music_explorer/cli.rb, line 85
def display_genres(artist)
  if artist.genres
    puts
    puts "Spotify classifies #{artist.name} as having the following genres:"
    print_numbered_list(artist.genres)
  puts
  else
    puts
    puts "Genres not available for #{artist.name}"
  end
end
display_top_tracks(artist) click to toggle source
# File lib/music_explorer/cli.rb, line 73
def display_top_tracks(artist)
  if artist.top_tracks
    puts
    puts "#{artist.name}'s top 10 tracks on Spotify are:"
    print_numbered_list(artist.top_tracks)
  puts
  else
    puts
    puts "Top tracks not available for #{artist.name}"
  end
end
end_program() click to toggle source
# File lib/music_explorer/cli.rb, line 163
def end_program
  puts "Goodbye!"
  exit
end
get_numeric_input() click to toggle source
# File lib/music_explorer/cli.rb, line 153
def get_numeric_input
  get_user_input.to_i
end
get_user_input() click to toggle source
# File lib/music_explorer/cli.rb, line 149
def get_user_input
  gets.strip
end
print_numbered_list(array) click to toggle source
program_options() click to toggle source
# File lib/music_explorer/cli.rb, line 10
def program_options
  while true
    puts
    puts "Please select an option (1-3)"
    puts "1. Search for an artist"
    puts "2. View all artists you have explored"
    puts "3. Leave program"
    puts
    user_choice = get_numeric_input
    case user_choice
    when 1
      search_artists
    when 2
      view_all_artists
    when 3
      end_program
    end
  end
end
search_artists(artist_query = nil) click to toggle source
# File lib/music_explorer/cli.rb, line 30
def search_artists(artist_query = nil)
  if artist_query == nil
    puts
    puts "What artist would you like more info about?"
    puts
    artist_query = self.get_user_input
  end
  artist = MusicExplorer::Artist.create_artist(artist_query)
  display_artist(artist)
  artist_options(artist)
end
view_all_artists() click to toggle source
# File lib/music_explorer/cli.rb, line 140
def view_all_artists
  puts
  puts "Artists explored in this session:"
  MusicExplorer::Artist.all.sort_by {|artist| artist.name}.each_with_index do |artist, index|
    puts "#{artist.name}"
  end
  puts
end