Class: Top100::CLI
- Inherits:
-
Object
- Object
- Top100::CLI
- Defined in:
- lib/top_100/cli.rb
Instance Attribute Summary collapse
-
#current_hits ⇒ Object
Returns the value of attribute current_hits.
-
#scraper ⇒ Object
Returns the value of attribute scraper.
-
#tracker ⇒ Object
Returns the value of attribute tracker.
Instance Method Summary collapse
- #call ⇒ Object
- #display_artist(rank) ⇒ 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 9 |
# File 'lib/top_100/cli.rb', line 5 def initialize @tracker = 0 @scraper = Top100::BillboardScraper.new @current_hits = self.scraper.scrape_from_chart_page end |
Instance Attribute Details
#current_hits ⇒ Object
Returns the value of attribute current_hits.
2 3 4 |
# File 'lib/top_100/cli.rb', line 2 def current_hits @current_hits end |
#scraper ⇒ Object
Returns the value of attribute scraper.
2 3 4 |
# File 'lib/top_100/cli.rb', line 2 def scraper @scraper end |
#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
12 13 14 15 16 |
# File 'lib/top_100/cli.rb', line 12 def call puts "Welcome to the Billboard Hot 100. Now outputting the top twenty songs..." display_chart end |
#display_artist(rank) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/top_100/cli.rb', line 31 def display_artist(rank) artist = Top100::Artist.create_artist(rank) if artist == nil puts "Invalid input" else artist.display_details end puts "--------------------------------" end |
#display_chart ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/top_100/cli.rb', line 18 def display_chart if self.tracker >= 100 puts "There are no more songs to display." else 20.times do hit = self.current_hits[self.tracker] puts "##{hit[:current_rank]}: #{hit[:song_name]} by #{hit[:song_artist]}. Previously number #{hit[:last_week_rank]} last week." puts "--------------------------------" self.tracker += 1 end end end |
#present_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/top_100/cli.rb', line 41 def puts "Options: 1. type in 'exit' to exit. 2. type in 'next' for the next twenty songs. 3. type in the number of a song for an artist you would like to learn more about." choice = gets.chomp if choice == 'exit' puts "Now exiting..." elsif choice == 'next' display_chart elsif choice.match(/\d+/) display_artist(choice.match(/\d+/)[0]) else puts "Unknown command. Try again." end end |