Class: CatalogPage

Inherits:
ItemsPage show all
Defined in:
lib/etvnet_seek/core/catalog_page.rb

Direct Known Subclasses

SearchPage

Constant Summary collapse

CATALOG_URL =
BASE_URL + "/catalog/"

Constants inherited from Page

Page::BASE_URL

Instance Attribute Summary

Attributes inherited from Page

#document

Attributes inherited from ServiceCall

#url

Instance Method Summary collapse

Methods inherited from ItemsPage

#categories, #category_breadcrumbs, #description, #navigation_menu, #page_browser, #page_title, #see_too_items, #title, #title_items

Methods inherited from ServiceCall

#get, #post

Constructor Details

#initialize(url = CATALOG_URL) ⇒ CatalogPage

Returns a new instance of CatalogPage.



4
5
6
# File 'lib/etvnet_seek/core/catalog_page.rb', line 4

def initialize url = CATALOG_URL
  super(url)
end

Instance Method Details

#itemsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/etvnet_seek/core/catalog_page.rb', line 8

def items
  list = []

  document.css(".conteiner #results #table-onecolumn tr").each_with_index do |item, index|
    next if index == 0

    showtime = item.css("td[1]").text.strip
    rating_image = item.css("td[3] img").at(0) ? item.css("td[3] img").at(0).attributes['src'].value.strip : ""
    rating = item.css("td[4]") ? item.css("td[4]").text.strip : ""
    name = item.css("td[2]").text.strip
    duration = item.css("td[5]") ? item.css("td[5]").text.strip : ""
    link = item.css("td[2] a").at(0)

    unless link.nil?
      href = link.attributes['href'].value
      digit_scan = name.scan(/\((\d*).*\)/)[0]
      amount_expr = digit_scan.nil? ? 0 : digit_scan[0].to_i
      folder = (amount_expr > 1) ? true : false

      record = BrowseMediaItem.new(name, href)
      record.folder = folder
      record.showtime = showtime
      record.duration = duration
      record.rating_image = rating_image
      record.rating = rating

      list << record
    end
  end

  list
end