Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/top_100/cli.rb
Instance Attribute Summary collapse
-
#tracker ⇒ Object
Returns the value of attribute tracker.
Instance Method Summary collapse
- #call ⇒ Object
- #display_artist(name) ⇒ Object
- #display_chart ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #present_options ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
5 6 7 8 |
# File 'lib/top_100/cli.rb', line 5 def initialize @tracker = 0 BillboardScraper.scrape_from_chart_page end |
Instance Attribute Details
#tracker ⇒ Object
Returns the value of attribute tracker.
2 3 4 |
# File 'lib/top_100/cli.rb', line 2 def tracker @tracker end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 |
# File 'lib/top_100/cli.rb', line 10 def call puts "Welcome to the Billboard Hot 100. Now outputting the top twenty songs..." display_chart end |
#display_artist(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/top_100/cli.rb', line 27 def display_artist(name) artist = Artist.find_or_create(name) artist.name == nil ? puts("Artist not found.") : artist.display_details puts "--------------------------------" end |
#display_chart ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/top_100/cli.rb', line 16 def display_chart if self.tracker >= 100 puts "There are no more songs to display." else 20.times do Song.all[self.tracker].display self.tracker += 1 end end end |
#present_options ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/top_100/cli.rb', line 33 def puts "Options: 1. type in 'exit' to exit. 2. type in 'next' for the next twenty songs. 3. type 'song' to play a song sample. 4. type in the full artist title of a song to learn more about the main artist." choice = gets.chomp case choice when 'exit' puts "Now exiting..." when 'next' display_chart when 'song' puts "Enter the chart number of the song you would like to play." rank = gets.chomp Song.play(rank) else begin display_artist(choice) # catches issues using OpenURI to access certain artist pages or issues with making frequent requests rescue OpenURI::HTTPError => error puts "Sorry, we're having trouble displaying this artist's details." end end end |