Class: Watchmob::GSMArenaPage
- Inherits:
-
Page
- Object
- Page
- Watchmob::GSMArenaPage
show all
- Defined in:
- lib/watchmob/gsmarena_page.rb
Instance Attribute Summary
Attributes inherited from Page
#document, #uri
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Page
#initialize
Constructor Details
This class inherits a constructor from Watchmob::Page
Class Method Details
.find(phrase) ⇒ Object
6
7
8
9
10
|
# File 'lib/watchmob/gsmarena_page.rb', line 6
def self.find(phrase)
search = GSMArenaSearchPage.search(phrase)
uri = search.first_result_uri
new(uri)
end
|
Instance Method Details
#autofocus ⇒ Object
61
62
63
64
65
|
# File 'lib/watchmob/gsmarena_page.rb', line 61
def autofocus
property "Primary" do |text|
!!(text =~ /autofocus/)
end
end
|
#average_time(text) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/watchmob/gsmarena_page.rb', line 48
def average_time(text)
minutes = text.scan(/(\d+)\s*h\s*(\d+\s*min)?/).map do |hours, mins=0|
hours.to_f * 60 + mins.to_f
end
unless minutes.empty?
sum = minutes.inject :+
return sum.to_f / minutes.size
end
nil
end
|
#battery_capacity ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/watchmob/gsmarena_page.rb', line 28
def battery_capacity
property "Battery" do |text|
text.match /(\d+)\s*mAh/i do |md|
return md[1].to_f
end
end
end
|
#mass ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/watchmob/gsmarena_page.rb', line 20
def mass
property "Weight" do |text|
text.match /(\d+)\s*g/ do |md|
return md[1].to_f
end
end
end
|
#name ⇒ Object
16
17
18
|
# File 'lib/watchmob/gsmarena_page.rb', line 16
def name
document.at_css("h1").andand.inner_text
end
|
#property(name) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/watchmob/gsmarena_page.rb', line 67
def property(name)
found = nil
document.css("#specs-list tr").each do |tr|
cells = [tr.at_css("th"), tr.at_css(".ttl")]
if cells.any? { |c| c.andand.inner_text.to_s.strip == name }
value = tr.at_css(".nfo").inner_text
unless value.nil?
raise PropertyError, "Property named #{name} has been matched " +
"more than once on GSM arena page #{uri}" if found
found = yield value
end
end
end
found
end
|
#stand_by ⇒ Object
36
37
38
39
40
|
# File 'lib/watchmob/gsmarena_page.rb', line 36
def stand_by
property "Stand-by" do |text|
average_time text
end
end
|
#talk_time ⇒ Object
42
43
44
45
46
|
# File 'lib/watchmob/gsmarena_page.rb', line 42
def talk_time
property "Talk time" do |text|
average_time text
end
end
|
#title ⇒ Object
12
13
14
|
# File 'lib/watchmob/gsmarena_page.rb', line 12
def title
"GSMArena"
end
|