Class: Watchmob::GSMArenaSearchPage

Inherits:
Page
  • Object
show all
Defined in:
lib/watchmob/gsmarena_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) ⇒ GSMArenaSearchPage

Returns a new instance of GSMArenaSearchPage.



10
11
12
13
# File 'lib/watchmob/gsmarena_search_page.rb', line 10

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

Instance Attribute Details

#phraseObject (readonly)

Returns the value of attribute phrase.



15
16
17
# File 'lib/watchmob/gsmarena_search_page.rb', line 15

def phrase
  @phrase
end

Class Method Details

.search(phrase) ⇒ Object



5
6
7
8
# File 'lib/watchmob/gsmarena_search_page.rb', line 5

def self.search(phrase)
  encoded_phrase = URI.encode_www_form_component(phrase)
  new("http://www.gsmarena.com/results.php3?sQuickSearch=no&sName=#{encoded_phrase}", phrase)
end

Instance Method Details

#first_result_uriObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/watchmob/gsmarena_search_page.rb', line 17

def first_result_uri
  if document.at_css("#specs-list")
    uri
  else
    path = document.css("#mid-col .makers li a").
      map { |a| a.attr("href") }.
      first

    if path
      URI.parse("http://www.gsmarena.com/#{path}")
    else
      raise NotFoundError, "There were no phones for #{phrase.inspect} on GSM arena"
    end
  end
end