Class: HotSongs::CLI
- Inherits:
-
Object
- Object
- HotSongs::CLI
- Defined in:
- lib/hot_songs/cli.rb
Instance Attribute Summary collapse
-
#genres ⇒ Object
Returns the value of attribute genres.
Instance Method Summary collapse
- #about ⇒ Object
- #display_chart_history(song, artist, chart_history, genre) ⇒ Object
- #display_menu ⇒ Object
- #display_songs(genre) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #main_loop ⇒ Object
- #user_input ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
5 6 7 |
# File 'lib/hot_songs/cli.rb', line 5 def initialize @genres = %w{ Pop Country Rock R&B/Rap Dance/Electronic Latin Christian/Gospel } end |
Instance Attribute Details
#genres ⇒ Object
Returns the value of attribute genres.
3 4 5 |
# File 'lib/hot_songs/cli.rb', line 3 def genres @genres end |
Instance Method Details
#about ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hot_songs/cli.rb', line 9 def about system 'clear' puts "Hot Songs v1.0".center(125) puts "" puts "The week's most popular songs, based on radio airplay audience impressions as measured by Nielsen Music, sales data as compiled by Nielsen Music and streaming activity data from online music sources tracked by Nielsen Music. Songs are defined as current if they are newly-released titles, or songs receiving widespread airplay and/or sales activity for the first time.".center(421) 3.times {puts} end |
#display_chart_history(song, artist, chart_history, genre) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hot_songs/cli.rb', line 49 def display_chart_history(song, artist, chart_history, genre) system 'clear' puts "#{song} - #{artist}".center(125) puts puts "*****Chart History******".center(125) puts chart_history.each_with_index do |stat, index| next if index.odd? puts "#{stat} -- #{chart_history[index+1]}".center(125) puts end puts "Press enter to return to song list".center(125) gets.chomp display_songs(genre) end |
#display_menu ⇒ Object
20 21 22 23 24 |
# File 'lib/hot_songs/cli.rb', line 20 def genres.each.with_index(1) { |genre, index| puts "#{index}. #{genre}".center(125)} puts user_input end |
#display_songs(genre) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hot_songs/cli.rb', line 35 def display_songs(genre) puts songs, artists, title, week, chart_history = HotSongs::Songs.scrape_songs_artists(genre) system 'clear' puts "Hottest #{genres[genre.to_i-1]} songs for the week of #{week}".center(125) puts songs.each.with_index(1) { |song, index| puts "#{index}. #{song} -- #{artists[index-1]}".center(125)} 2.times {puts} puts "Press enter to return to genre list or enter a number to see the song's chart history".center(125) answer = gets.chomp display_chart_history(songs[answer.to_i-1], artists[answer.to_i-1], chart_history[answer.to_i-1], genre) if ('1'..songs.count.to_s).include?(answer) system 'clear' end |
#main_loop ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/hot_songs/cli.rb', line 65 def main_loop about loop do break if %w{q quit}.include?() end system 'clear' puts "Goodbye!".center(125) end |
#user_input ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/hot_songs/cli.rb', line 26 def user_input begin print "Please pick a genre to see the week's hottest songs(1-7)('q' or quit to exit): ".center(125) choice = gets.chomp.downcase return choice if choice == 'q' || choice == 'quit' end until ('1'..'7').to_a.include?(choice) display_songs(choice) end |