Module: Korfzone::Scraper::GamesPage

Included in:
Page
Defined in:
lib/korfzone/scraper/games_page.rb

Overview

Code to extract all games from one page

Instance Method Summary collapse

Instance Method Details

#categoryObject



8
9
10
11
# File 'lib/korfzone/scraper/games_page.rb', line 8

def category
  extract_category_and_competition if @category.nil?
  @category
end

#competitionObject



13
14
15
16
# File 'lib/korfzone/scraper/games_page.rb', line 13

def competition
  extract_category_and_competition if @competition.nil?
  @competition
end

#gamesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/korfzone/scraper/games_page.rb', line 18

def games
  Array.new.tap do |games|
    rows = document.xpath( '//*[@id="ContentPlaceHolder1_UpdatePanel1"]/table[2]/tr[td[ contains( @class, "gameLeagueHeader" ) or contains( @class, "rptItem" ) or contains( @class, "rptAltItem" )]]' )
    rows.inject( nil ) do |division,row|
      if division.nil? || row.css( 'td.gameLeagueHeader' ).any?
        row.text.strip.gsub( /\s+/, ' ' ) 
      else
        division.tap do |division|
          attributes = parse_game_row( row )
          unless attributes.nil?
            attributes.merge!( division: division, category: category.to_s, competition: competition )
            yield attributes if block_given?
            games << attributes
          end # end unless attributes nil
        end # end division tap
      end # if division.nil?
    end # end inject
  end # end games tap
end