Class: BillboardChartScraper
- Inherits:
-
Object
- Object
- BillboardChartScraper
- Defined in:
- lib/billboard_chart/billboard_chart_scraper.rb
Overview
encoding: utf-8
Instance Attribute Summary collapse
-
#scraped_data ⇒ Object
Returns the value of attribute scraped_data.
Instance Method Summary collapse
-
#get_artists ⇒ Object
Scrape Methods ============= #.
- #get_singles ⇒ Object
-
#initialize(url) ⇒ BillboardChartScraper
constructor
A new instance of BillboardChartScraper.
- #merge_artists_and_singles ⇒ Object
-
#top_ten ⇒ Object
Display Methods ============= #.
Constructor Details
#initialize(url) ⇒ BillboardChartScraper
Returns a new instance of BillboardChartScraper.
9 10 11 12 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 9 def initialize(url) @scraped_data = Nokogiri::HTML(open(url)) top_ten end |
Instance Attribute Details
#scraped_data ⇒ Object
Returns the value of attribute scraped_data.
7 8 9 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 7 def scraped_data @scraped_data end |
Instance Method Details
#get_artists ⇒ Object
Scrape Methods ============= #
16 17 18 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 16 def get_artists @scraped_data.css("p.chart_info a").collect {|artist| artist.text} end |
#get_singles ⇒ Object
20 21 22 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 20 def get_singles @scraped_data.css("h1").collect {|single| single.text}[1..10] end |
#merge_artists_and_singles ⇒ Object
24 25 26 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 24 def merge_artists_and_singles Hash[get_artists.zip(get_singles)] end |
#top_ten ⇒ Object
Display Methods ============= #
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/billboard_chart/billboard_chart_scraper.rb', line 30 def top_ten puts "\n" puts "✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭".yellow puts "\n" puts " ♫ Top 10 Billboard Hot 100 Singles Chart: ♫ " puts " (#{DateTime.now.strftime('%m/%d/%Y')}) ".red puts "\n" i = 0 while i < 10 merge_artists_and_singles.each do |artist, single| puts "#{i+1}. #{artist} - #{single}" i += 1 end puts "\n" puts "✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭ ✭".yellow puts "\n" end end |