Module: Korfzone::Scraper::BlockPage

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

Overview

Code to handle links to different block pages.

Games on the korfbalkorfbal.be website are divided into blocks. Every block has its own page. At the top of every page links to every other block can be found.

Instance Method Summary collapse

Instance Method Details

#block_pages {|A| ... } ⇒ Array<Page>

Extracts the uri’s of all block pages found at the top of this page encapsulated in Page objects.

Yield Parameters:

  • A (Page)

    page containing games for one block

Returns:

  • (Array<Page>)

    An array containing other block pages



31
32
33
34
35
# File 'lib/korfzone/scraper/block_page.rb', line 31

def block_pages
  block_uris.map do |uri| 
    Page.new( uri.to_s ).tap { |uri| yield uri if block_given? }
  end
end

#block_uris {|An| ... } ⇒ Array<URI>

Extracts the uri’s of all block pages found at the top of this page.

Yield Parameters:

  • An (URI)

    uri found on this page

Returns:

  • (Array<URI>)

    An array containing all uri’s found on this page



16
17
18
19
20
21
22
23
24
# File 'lib/korfzone/scraper/block_page.rb', line 16

def block_uris
  Array.new.tap do |block_urls|
    document.css( '.block @href' ).each do |block_element|
      block_url = resolve_uri block_element.value
      yield block_url if block_given?
      block_urls << block_url
    end
  end
end