Class: Watchmob::HeurekaSearchPage

Inherits:
Page
  • Object
show all
Defined in:
lib/watchmob/heureka_search_page.rb

Instance Attribute Summary collapse

Attributes inherited from Page

#document, #uri

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, phrase = nil) ⇒ HeurekaSearchPage

Returns a new instance of HeurekaSearchPage.



11
12
13
14
# File 'lib/watchmob/heureka_search_page.rb', line 11

def initialize(uri, phrase = nil)
  super(uri)
  @phrase = phrase
end

Instance Attribute Details

#phraseObject (readonly)

Returns the value of attribute phrase.



16
17
18
# File 'lib/watchmob/heureka_search_page.rb', line 16

def phrase
  @phrase
end

Class Method Details

.search(phrase) ⇒ Object



6
7
8
9
# File 'lib/watchmob/heureka_search_page.rb', line 6

def self.search(phrase)
  encoded_phrase = URI.encode_www_form_component(phrase)
  new("http://mobilni-telefony.heureka.cz/f:q:#{encoded_phrase}", phrase)
end

Instance Method Details

#first_result_uriObject

Raises:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/watchmob/heureka_search_page.rb', line 18

def first_result_uri
  if document.at_css("#product-container")
    found_uri = document.css("#product-container .p").
      map { |search_result| URI.parse(search_result.at_css("h2 a").attr("href")) }.
      first

    return found_uri unless found_uri.nil?
  end

  raise NotFoundError, "There were no smartphones for #{phrase.inspect} on Heureka"
end