class Hot100CLI::CLI

Public Instance Methods

ask_to_play_song(song) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 122
def ask_to_play_song(song)
  puts ' '
  puts 'To listen to this song on spotify, type \'listen\'. To watch this song\'s music video, type \'watch\'. Otherwise, type \'exit\'.'
  puts ' '
  input = gets.chomp
  if input == 'listen'
    launch_spotify_link(song)
  elsif input == 'watch'
    launch_vevo_link(song)
  end
end
call() click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 4
def call
  puts 'Starting...'
  puts ' '
  BillboardScraper.new
  greeting
  display_songs_in_range("1-10")
  puts "You may now choose to view the rest of the list or get more information on any of the songs on the list by typing the appropriate command. For a list of commands, type 'help'."
  puts " "
  menu
  farewell
end
chart_index_if_valid(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 184
def chart_index_if_valid(input)
  if input.to_i.between?(1,100) 
        more_info_song(input)
      else
        puts "Not a valid entry, choose a number between 1 and 100"
      end
end
chart_range_if_valid(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 176
def chart_range_if_valid(input)
  if valid_range?(split_input_to_range(input))
    display_songs_in_range(input)
  else
    puts "That number range feels off. Check your numbers and format and try again."
  end
end
display_artist_list() click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 170
def display_artist_list
  Artist.all.each do |artist|
    puts artist.name
  end
end
display_artist_songs(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 64
def display_artist_songs(input)
  artist = Artist.find_by_name(input.split('artist ')[1])
  if artist
    puts ' '
    puts "This week, #{artist.name} charted these songs:"
    puts ' '
    artist.songs.each { |song| puts "#{song.rank}. #{song.title}" }
    puts ' '
  else
    puts ' '
    puts "That artist isn't on the charts this week. Maybe next week?"
    puts ' '
  end
end
display_songs(songs) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 115
def display_songs(songs)
  songs.each { |song| puts "#{song.rank}. #{song.title} - #{song.artist_listing}" }
  puts " "
  puts "For more info on a song, please type it's rank or type 'song ' then the song's title."
end
display_songs_in_range(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 107
def display_songs_in_range(input)
  range = split_input_to_range(input)
  songs = Song.all.select do |song|
    song.rank >= range[0] && range[1] >= song.rank
  end 
  display_songs(songs)
end
farewell() click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 60
def farewell
  puts "See You Next Tuesday."
end
greeting() click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 16
def greeting
  puts "Hello, Welcome to the Billboard Top 100 CLI"
  puts " "
  puts "These are the top ten songs this week!"
  puts " "
  puts "For the full list type 'hot 100'!"
end
list_commands() click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 52
def list_commands
  puts "To see the full billboard list, type hot 100. Otherwise enter a range of entries to view"
  puts "For more info on a song, type 'song' followed by that song's name or chart position"
  puts "To see all charted songs by a particular artist, type 'artist' followed by that artist's name"
  puts "To exit, simply type exit"
  puts "For help, type help, but I think you have this one figured out already."
end
menu() click to toggle source
more_info_song(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 79
def more_info_song(input)
  if !input[/\Asong/]
    song = Song.find_by_rank(input)
  else
    song = Song.find_by_title(input.split("song ")[1])
  end
  if song
    puts ' '
    puts "     #{song.title}"
    puts  "          By #{song.artist_listing}"
    puts ' '
    puts "This week, #{song.title} was number #{song.rank} on the Billboard Top 100 Charts."
    puts ' '
    song_history(song)
    ask_to_play_song(song)
  else
    puts "That song doesn't seem to be on the charts this week."
  end
end
song_history(song) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 160
def song_history(song) #need to add logic for a song returning to the top 100
  if song.chart_status.is_new?
    puts "This is #{song.title}'s debut week on the Hot 100 charts!"
  else
    song.chart_status.position_change
    song.chart_status.peak_status
    song.chart_status.weeks_status
  end
end
split_input_to_range(input) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 103
def split_input_to_range(input)
  input.split("-").map { |num| num.to_i }
end
valid_range?(range) click to toggle source
# File lib/Hot_100_CLI/cli.rb, line 99
def valid_range?(range)
  range[0].between?(1,99) && range[1].between?(2,100) && range[0] < range[1]
end