Class: Alvalaxia::Scrapper
- Inherits:
-
Object
- Object
- Alvalaxia::Scrapper
- Defined in:
- lib/alvalaxia/scrapper.rb
Constant Summary collapse
- USER_AGENT =
page that lists the next SCP games
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1'
- NEXT_GAMES_URL =
'http://www.zerozero.pt/equipa.php?grp=0&ond=c&compet_id_jogos=0&epoca_id=141&id=16&menu=nextmatches&type=season'
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize ⇒ Scrapper
constructor
A new instance of Scrapper.
Constructor Details
#initialize ⇒ Scrapper
Returns a new instance of Scrapper.
16 17 18 |
# File 'lib/alvalaxia/scrapper.rb', line 16 def initialize @games = Array.new end |
Instance Method Details
#fetch ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/alvalaxia/scrapper.rb', line 20 def fetch doc = Nokogiri::HTML(open(NEXT_GAMES_URL, 'User-Agent' => USER_AGENT)) doc.css('table.statsn tr').each do |item| tds = Array.new item.css('td').each do |td| tds << td.text end unless tds.empty? # index 0 contains date, 5 the opponent and 6 the competition game = Alvalaxia::Game.new(tds[0], tds[5], tds[6]) @games << game end end if @games.empty? raise UnableToParseDataError end return @games end |