Class: Watchmob::Smartphone

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

Constant Summary collapse

SPEC_PAGES =
[HeurekaPage, GSMArenaPage]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aukro_page, spec_pages) ⇒ Smartphone

Returns a new instance of Smartphone.



31
32
33
34
# File 'lib/watchmob/smartphone.rb', line 31

def initialize(aukro_page, spec_pages)
  @aukro_page = aukro_page
  @spec_pages = spec_pages
end

Instance Attribute Details

#aukro_pageObject (readonly)

Returns the value of attribute aukro_page.



36
37
38
# File 'lib/watchmob/smartphone.rb', line 36

def aukro_page
  @aukro_page
end

#spec_pagesObject (readonly)

Returns the value of attribute spec_pages.



37
38
39
# File 'lib/watchmob/smartphone.rb', line 37

def spec_pages
  @spec_pages
end

Class Method Details

.find(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watchmob/smartphone.rb', line 10

def self.find(params)
  unless params["aukro"] and params["phone"]
    raise ArgumentError, "I want parameters 'aukro' and 'phone', got #{params.inspect}"
  end

  aukro_page = AukroPage.new(URI.parse(params["aukro"]))
  spec_pages = SPEC_PAGES.map { |spec_page|
    begin
      spec_page.find(params["phone"])
    rescue NotFoundError
      nil
    end
   }.select { |s| !s.nil? }

  unless spec_pages.empty?
    new(aukro_page, spec_pages)
  else
    raise NotFoundError, "Smartphone #{params["phone"]} <#{params["aukro"]}> was not found anywhere"
  end
end

Instance Method Details

#aukro_deadlineObject



51
52
53
# File 'lib/watchmob/smartphone.rb', line 51

def aukro_deadline
  @aukro_page.deadline
end

#aukro_finished?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/watchmob/smartphone.rb', line 43

def aukro_finished?
  @aukro_page.finished?
end

#aukro_priceObject



47
48
49
# File 'lib/watchmob/smartphone.rb', line 47

def aukro_price
  @aukro_page.price
end

#aukro_uriObject



55
56
57
# File 'lib/watchmob/smartphone.rb', line 55

def aukro_uri
  @aukro_page.uri
end

#autofocusObject



75
76
77
# File 'lib/watchmob/smartphone.rb', line 75

def autofocus
  boolean :autofocus
end

#battery_capacityObject



63
64
65
# File 'lib/watchmob/smartphone.rb', line 63

def battery_capacity
  average :battery_capacity
end

#massObject



59
60
61
# File 'lib/watchmob/smartphone.rb', line 59

def mass
  average :mass
end

#nameObject



39
40
41
# File 'lib/watchmob/smartphone.rb', line 39

def name
  @spec_pages.first.name
end

#stand_byObject



67
68
69
# File 'lib/watchmob/smartphone.rb', line 67

def stand_by
  average :stand_by
end

#talk_timeObject



71
72
73
# File 'lib/watchmob/smartphone.rb', line 71

def talk_time
  average :talk_time
end