Class: DutchTop40::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/dutch_top40/scraper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#last_weeks_rankObject

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

#listedObject

Returns the value of attribute listed.



3
4
5
# File 'lib/dutch_top40/scraper.rb', line 3

def listed
  @listed
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/dutch_top40/scraper.rb', line 3

def name
  @name
end

#titleObject

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_songsObject



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