Class: DutchTop40::Scraper
- Inherits:
-
Object
- Object
- DutchTop40::Scraper
- Defined in:
- lib/dutch_top40/scraper.rb
Instance Attribute Summary collapse
-
#last_weeks_rank ⇒ Object
Returns the value of attribute last_weeks_rank.
-
#listed ⇒ Object
Returns the value of attribute listed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Attribute Details
#last_weeks_rank ⇒ Object
Returns the value of attribute last_weeks_rank.
3 4 5 |
# File 'lib/dutch_top40/scraper.rb', line 3 def last_weeks_rank @last_weeks_rank end |
#listed ⇒ Object
Returns the value of attribute listed.
3 4 5 |
# File 'lib/dutch_top40/scraper.rb', line 3 def listed @listed end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/dutch_top40/scraper.rb', line 3 def name @name end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/dutch_top40/scraper.rb', line 3 def title @title end |
Class Method Details
.scrape_songs ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dutch_top40/scraper.rb', line 5 def self.scrape_songs doc = Nokogiri::HTML(open("http://top40.nl")) doc.search('.listScroller').search('.top40List').each do |song| title = song.search('.songtitle').text.strip name = song.search('.artist').text listed = song.search('.details').text.split(' | ')[1].gsub(/Aantal weken: /,'').strip if song.search('.details').text.split(' | ')[0].gsub(/Vorige week: #/,'').strip == '-' last_weeks_rank = 'new entry' else last_weeks_rank = song.search('.details').text.split(' | ')[0].gsub(/Vorige week: #/,'').strip end DutchTop40::Songs.new(title, name, listed, last_weeks_rank) end end |