wurfl_device 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +2 -2
- data/README.md +31 -7
- data/config/unicorn.conf.rb +13 -7
- data/lib/wurfl_device/cache.rb +215 -0
- data/lib/wurfl_device/capability.rb +5 -1
- data/lib/wurfl_device/cli.rb +59 -67
- data/lib/wurfl_device/settings.rb +595 -0
- data/lib/wurfl_device/ui.rb +1 -0
- data/lib/wurfl_device/user_agent.rb +75 -8
- data/lib/wurfl_device/user_agent_matcher.rb +153 -191
- data/lib/wurfl_device/version.rb +1 -1
- data/lib/wurfl_device/web_service.rb +10 -44
- data/lib/wurfl_device/xml_loader.rb +44 -37
- data/lib/wurfl_device.rb +41 -236
- data/spec/cache/device_spec.rb +7 -31
- data/spec/cache/user_agents_spec.rb +27 -0
- data/spec/spec_helper.rb +6 -1
- data/wurfl_device.gemspec +6 -3
- metadata +52 -38
- data/lib/wurfl_device/constants.rb +0 -43
- data/lib/wurfl_device/device.rb +0 -83
@@ -1,76 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'text'
|
2
3
|
|
3
4
|
module WurflDevice
|
4
5
|
class UserAgentMatcher
|
5
|
-
attr_accessor :user_agent, :
|
6
|
+
attr_accessor :user_agent, :capabilities
|
6
7
|
|
7
8
|
def match(user_agent)
|
8
|
-
|
9
|
+
user_agent = UserAgent.new(user_agent) unless user_agent.kind_of?(UserAgent)
|
9
10
|
|
10
|
-
|
11
|
-
@device = WurflDevice.get_device_from_ua_cache(@user_agent)
|
12
|
-
@device = WurflDevice.get_device_from_ua_cache(@user_agent.cleaned) if @device.nil?
|
11
|
+
@user_agent = user_agent
|
13
12
|
|
14
|
-
#
|
15
|
-
|
13
|
+
# exact match
|
14
|
+
capabilities = WurflDevice::Cache::UserAgents.keys_values(user_agent)
|
16
15
|
|
17
|
-
|
18
|
-
if
|
19
|
-
|
20
|
-
matcher = "matcher_#{index_matcher.downcase}"
|
16
|
+
matched_ua = nil
|
17
|
+
if capabilities['id'].nil? || capabilities['id'].empty?
|
18
|
+
matcher = "matcher_#{user_agent.manufacturer.downcase}"
|
21
19
|
if self.respond_to?(matcher)
|
22
|
-
self.send(matcher,
|
20
|
+
matched_ua = self.send(matcher, user_agent)
|
23
21
|
else
|
24
|
-
if
|
22
|
+
if user_agent =~ /^Mozilla/i
|
25
23
|
tolerance = 5
|
26
|
-
|
24
|
+
matched_ua = ld_match(user_agent, tolerance)
|
27
25
|
else
|
28
26
|
tolerance = @user_agent.first_slash
|
29
|
-
|
27
|
+
matched_ua = ris_match(@user_agent, tolerance)
|
30
28
|
end
|
31
29
|
end
|
30
|
+
|
31
|
+
unless matched_ua.nil?
|
32
|
+
capabilities = WurflDevice::Cache::UserAgents.keys_values(matched_ua)
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
last_attempts(@user_agent)
|
36
|
+
if capabilities['id'].nil? || capabilities['id'].empty?
|
37
|
+
capabilities = WurflDevice::Cache::UserAgents.keys_values(last_attempts(user_agent.cleaned))
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
if capabilities.count == 1
|
41
|
+
@capabilities = Cache.build_capabilities(capabilities['id'])
|
42
|
+
Cache.update_actual_capabilities(user_agent, @capabilities)
|
43
|
+
else
|
44
|
+
@capabilities = WurflDevice::Cache.parse_actual_capabilities(capabilities)
|
45
|
+
end
|
40
46
|
|
41
47
|
return self
|
42
48
|
end
|
43
49
|
|
44
50
|
def ris_match(user_agent, tolerance=nil)
|
45
|
-
tolerance = WurflDevice::
|
51
|
+
tolerance = WurflDevice::Settings::WORST_MATCH if tolerance.nil?
|
46
52
|
device = nil
|
47
|
-
user_agent_list = WurflDevice.
|
53
|
+
user_agent_list = WurflDevice::Cache::UserAgentsManufacturers.keys(user_agent.manufacturer).sort
|
48
54
|
curlen = user_agent.length
|
49
55
|
while curlen >= tolerance
|
50
56
|
user_agent_list.each do |ua|
|
51
57
|
next if ua.length < curlen
|
52
58
|
if ua.index(user_agent) == 0
|
53
|
-
|
54
|
-
break
|
59
|
+
return ua
|
55
60
|
end
|
56
61
|
end
|
57
|
-
break unless device.nil?
|
58
62
|
user_agent = user_agent.slice(0, curlen-1)
|
59
63
|
curlen = user_agent.length
|
60
64
|
end
|
61
|
-
return
|
65
|
+
return nil
|
62
66
|
end
|
63
67
|
|
64
68
|
def ld_match(user_agent, tolerance=nil)
|
65
|
-
tolerance = WurflDevice::
|
66
|
-
|
67
|
-
user_agent_list = WurflDevice.get_user_agents_in_index(get_index(user_agent))
|
68
|
-
|
69
|
+
tolerance = WurflDevice::Settings::WORST_MATCH if tolerance.nil?
|
70
|
+
user_agent_list = WurflDevice::Cache::UserAgentsManufacturers.keys(user_agent.manufacturer).sort
|
69
71
|
length = user_agent.length
|
70
72
|
best = tolerance
|
71
73
|
current = 0
|
72
74
|
match = nil
|
73
|
-
user_agent_list.
|
75
|
+
user_agent_list.each do |ua|
|
74
76
|
next if !ua.length.between?(length - tolerance, length + tolerance)
|
75
77
|
current = Text::Levenshtein.distance(ua, user_agent)
|
76
78
|
if current <= best
|
@@ -78,66 +80,8 @@ module WurflDevice
|
|
78
80
|
match = ua
|
79
81
|
end
|
80
82
|
end
|
81
|
-
|
82
|
-
|
83
|
-
return device
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_index(user_agent)
|
87
|
-
ua = UserAgent.new(user_agent)
|
88
|
-
# Process MOBILE user agents
|
89
|
-
unless ua.is_desktop_browser?
|
90
|
-
return 'Nokia' if ua.contains('Nokia')
|
91
|
-
return 'Samsung' if ua.contains(['Samsung/SGH', 'SAMSUNG-SGH']) || ua.starts_with(['SEC-', 'Samsung', 'SAMSUNG', 'SPH', 'SGH', 'SCH']) || ua.starts_with('samsung', true)
|
92
|
-
return 'BlackBerry' if ua.contains('blackberry', true)
|
93
|
-
return 'SonyEricsson' if ua.contains('Sony')
|
94
|
-
return 'Motorola' if ua.starts_with(['Mot-', 'MOT-', 'MOTO', 'moto']) || ua.contains('Motorola')
|
95
|
-
|
96
|
-
return 'Alcatel' if ua.starts_with('alcatel', true)
|
97
|
-
return 'Apple' if ua.contains(['iPhone', 'iPod', 'iPad', '(iphone'])
|
98
|
-
return 'BenQ' if ua.starts_with('benq', true)
|
99
|
-
return 'DoCoMo' if ua.starts_with('DoCoMo')
|
100
|
-
return 'Grundig' if ua.starts_with('grundig', true)
|
101
|
-
return 'HTC' if ua.contains(['HTC', 'XV6875'])
|
102
|
-
return 'Kddi' if ua.contains('KDDI-')
|
103
|
-
return 'Kyocera' if ua.starts_with(['kyocera', 'QC-', 'KWC-'])
|
104
|
-
return 'LG' if ua.starts_with('lg', true)
|
105
|
-
return 'Mitsubishi' if ua.starts_with('Mitsu')
|
106
|
-
return 'Nec' if ua.starts_with(['NEC-', 'KGT'])
|
107
|
-
return 'Nintendo' if ua.contains('Nintendo') || (ua.starts_with('Mozilla/') && ua.starts_with('Nitro') && ua.starts_with('Opera'))
|
108
|
-
return 'Panasonic' if ua.contains('Panasonic')
|
109
|
-
return 'Pantech' if ua.starts_with(['Pantech', 'PT-', 'PANTECH', 'PG-'])
|
110
|
-
return 'Philips' if ua.starts_with('philips', true)
|
111
|
-
return 'Portalmmm' if ua.starts_with('portalmmm')
|
112
|
-
return 'Qtek' if ua.starts_with('Qtek')
|
113
|
-
return 'Sagem' if ua.starts_with('sagem', true)
|
114
|
-
return 'Sharp' if ua.starts_with('sharp', true)
|
115
|
-
return 'Siemens' if ua.starts_with('SIE-')
|
116
|
-
return 'SPV' if ua.starts_with('SPV')
|
117
|
-
return 'Toshiba' if ua.starts_with('Toshiba')
|
118
|
-
return 'Vodafone' if ua.starts_with('Vodafone')
|
119
|
-
|
120
|
-
# mobile browsers
|
121
|
-
return 'Android' if ua.contains('Android')
|
122
|
-
return 'OperaMini' if ua.contains(['Opera Mini', 'Opera Mobi'])
|
123
|
-
return 'WindowsCE' if ua.contains('Mozilla/') && ua.contains('Windows CE')
|
124
|
-
end
|
125
|
-
|
126
|
-
# Process Robots (Web Crawlers and the like)
|
127
|
-
return 'Bot' if ua.is_robot?
|
128
|
-
|
129
|
-
# Process NON-MOBILE user agents
|
130
|
-
unless ua.is_mobile_browser?
|
131
|
-
return 'MSIE' if ua.starts_with('Mozilla') && ua.contains('MSIE') && !ua.contains(['Opera', 'armv', 'MOTO', 'BREW'])
|
132
|
-
return 'Firefox' if ua.contains('Firefox') && !ua.contains(['Sony', 'Novarra', 'Opera'])
|
133
|
-
return 'Chrome' if ua.contains('Chrome')
|
134
|
-
return 'Konqueror' if ua.contains('Konqueror')
|
135
|
-
return 'Opera' if ua.contains('Opera')
|
136
|
-
return 'Safari' if ua.starts_with('Mozilla') && ua.contains('Safari')
|
137
|
-
return 'AOL' if ua.contains(['AOL', 'America Online']) || ua.contains('aol 9', true)
|
138
|
-
end
|
139
|
-
|
140
|
-
return 'CatchAll'
|
83
|
+
return match unless match.nil?
|
84
|
+
return nil
|
141
85
|
end
|
142
86
|
|
143
87
|
protected
|
@@ -190,19 +134,21 @@ module WurflDevice
|
|
190
134
|
when user_agent.contains(['Mozilla/4.0', 'Mozilla/5.0', 'Mozilla/6.0'])
|
191
135
|
'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
|
192
136
|
else
|
193
|
-
WurflDevice::
|
137
|
+
WurflDevice::Settings::GENERIC
|
194
138
|
end
|
195
|
-
|
139
|
+
|
140
|
+
return device_ua
|
196
141
|
end
|
197
142
|
|
198
143
|
# mobile user agents
|
199
144
|
def matcher_nokia(user_agent)
|
200
145
|
tolerance = user_agent.index_of_or_length(['/', ' '], user_agent.index('Nokia'))
|
201
|
-
|
146
|
+
return ris_match(user_agent, tolerance)
|
202
147
|
end
|
203
148
|
|
204
149
|
def matcher_samsung(user_agent)
|
205
150
|
tolerance = 0
|
151
|
+
matched_ua = nil
|
206
152
|
if user_agent.starts_with('SAMSUNG') || user_agent.starts_with('SEC-') || user_agent.starts_with('SCH-')
|
207
153
|
tolerance = user_agent.first_slash
|
208
154
|
elsif user_agent.starts_with('Samsung') || user_agent.starts_with('SPH') || user_agent.starts_with('SGH')
|
@@ -210,27 +156,29 @@ module WurflDevice
|
|
210
156
|
else
|
211
157
|
tolerance = user_agent.second_slash
|
212
158
|
end
|
213
|
-
|
214
|
-
if
|
159
|
+
matched_ua = ris_match(user_agent, tolerance)
|
160
|
+
if matched_ua.nil?
|
215
161
|
if user_agent.starts_with('SAMSUNG')
|
216
162
|
tolerance = 8
|
217
|
-
|
163
|
+
matched_ua = ld_match(user_agent, tolerance)
|
218
164
|
else
|
219
165
|
tolerance = user_agent.index_of_or_length('/', user_agent.index('Samsung'))
|
220
|
-
|
166
|
+
matched_ua = ris_match(user_agent, tolerance)
|
221
167
|
end
|
222
168
|
end
|
169
|
+
return matched_ua
|
223
170
|
end
|
224
171
|
|
225
172
|
def matcher_blackberry(user_agent)
|
226
173
|
tolerance = 0
|
174
|
+
matched_ua = nil
|
227
175
|
if user_agent.starts_with('BlackBerry')
|
228
176
|
tolerance = user_agent.ordinal_index_of(';', 3)
|
229
177
|
else
|
230
178
|
tolerance = user_agent.first_slash
|
231
179
|
end
|
232
|
-
|
233
|
-
if
|
180
|
+
matched_ua = ris_match(user_agent, tolerance)
|
181
|
+
if matched_ua.nil?
|
234
182
|
if user_agent =~ /Black[Bb]erry[^\/\s]+\/(\d\.\d)/
|
235
183
|
versions = {
|
236
184
|
'2.' => 'DO_NOT_MATCH_BLACKBERRY_2',
|
@@ -250,56 +198,61 @@ module WurflDevice
|
|
250
198
|
'6.' => 'DO_NOT_MATCH_BLACKBERRY_6',
|
251
199
|
}.each_pair do |vercode, device_ua|
|
252
200
|
if $1.index(vercode)
|
253
|
-
|
254
|
-
break
|
201
|
+
return device_ua
|
255
202
|
end
|
256
203
|
end
|
257
204
|
end
|
258
205
|
end
|
206
|
+
return matched_ua
|
259
207
|
end
|
260
208
|
|
261
209
|
def matcher_sonyericsson(user_agent)
|
262
210
|
tolerance = 0
|
211
|
+
matched_ua = nil
|
263
212
|
if user_agent.starts_with('SonyEricsson')
|
264
213
|
tolerance = user_agent.first_slash - 1
|
265
214
|
else
|
266
215
|
tolerance = user_agent.second_slash
|
267
216
|
end
|
268
|
-
|
269
|
-
if
|
217
|
+
matched_ua = ris_match(user_agent, tolerance)
|
218
|
+
if matched_ua.nil?
|
270
219
|
tolerance = 14
|
271
|
-
|
220
|
+
matched_ua = ris_match(user_agent, tolerance)
|
272
221
|
end
|
222
|
+
return matched_ua
|
273
223
|
end
|
274
224
|
|
275
225
|
def matcher_motorola(user_agent)
|
276
226
|
tolerance = 5
|
227
|
+
matched_ua = nil
|
277
228
|
if user_agent.starts_with('Mot-') || user_agent.starts_with('MOT-') || user_agent.starts_with('Motorola')
|
278
|
-
|
229
|
+
matched_ua = ris_match(user_agent, tolerance)
|
279
230
|
else
|
280
|
-
|
231
|
+
matched_ua = ld_match(user_agent, tolerance)
|
281
232
|
end
|
282
|
-
if
|
283
|
-
|
233
|
+
if matched_ua.nil?
|
234
|
+
return 'DO_NOT_MATCH_MIB_2_2' if user_agent.contains('MIB/2.2') || user_agent.contains('MIB/BER2.2')
|
284
235
|
end
|
236
|
+
return matched_ua
|
285
237
|
end
|
286
238
|
|
287
239
|
def matcher_alcatel(user_agent)
|
288
240
|
tolerance = user_agent.first_slash
|
289
|
-
|
241
|
+
return ris_match(user_agent, tolerance)
|
290
242
|
end
|
291
243
|
|
292
244
|
def matcher_apple(user_agent)
|
293
245
|
tolerance = 0
|
246
|
+
matched_ua = nil
|
294
247
|
if user_agent.starts_with('Apple')
|
295
248
|
tolerance = user_agent.ordinal_index_of(' ', 3)
|
296
249
|
tolerance = user_agent.length if tolerance == -1
|
297
250
|
else
|
298
251
|
tolerance = user_agent.ordinal_index_of(';', 0)
|
299
252
|
end
|
300
|
-
|
301
|
-
if
|
302
|
-
|
253
|
+
matched_ua = ris_match(user_agent, tolerance)
|
254
|
+
if matched_ua.nil?
|
255
|
+
matched_ua = case
|
303
256
|
when user_agent.contains('iPod')
|
304
257
|
'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3'
|
305
258
|
when user_agent.contains('iPad')
|
@@ -307,15 +260,15 @@ module WurflDevice
|
|
307
260
|
when user_agent.contains('iPhone')
|
308
261
|
'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538a Safari/419.3'
|
309
262
|
else
|
310
|
-
|
263
|
+
WurflDevice::Contants::GENERIC
|
311
264
|
end
|
312
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
313
265
|
end
|
266
|
+
return matched_ua
|
314
267
|
end
|
315
268
|
|
316
269
|
def matcher_benq(user_agent)
|
317
270
|
tolerance = user_agent.first_slash
|
318
|
-
|
271
|
+
return ris_match(user_agent, tolerance)
|
319
272
|
end
|
320
273
|
|
321
274
|
def matcher_docomo(user_agent)
|
@@ -325,31 +278,32 @@ module WurflDevice
|
|
325
278
|
else
|
326
279
|
tolerance = user_agent.first_open_paren
|
327
280
|
end
|
328
|
-
|
329
|
-
if
|
281
|
+
matched_ua = ris_match(user_agent, tolerance)
|
282
|
+
if matched_ua.nil?
|
330
283
|
version_index = 7
|
331
|
-
|
284
|
+
matched_ua = case
|
332
285
|
when user_agent[version_index] == '2'
|
333
286
|
'DO_NOT_MATCH_DOCOMO_GENERIC_JAP_2'
|
334
287
|
else
|
335
288
|
'DO_NOT_MATCH_DOCOMO_GENERIC_JAP_1'
|
336
289
|
end
|
337
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
338
290
|
end
|
291
|
+
return matched_ua
|
339
292
|
end
|
340
293
|
|
341
294
|
def matcher_grundig(user_agent)
|
342
295
|
tolerance = user_agent.first_slash
|
343
|
-
|
296
|
+
return ris_match(user_agent, tolerance)
|
344
297
|
end
|
345
298
|
|
346
299
|
def matcher_htc(user_agent)
|
347
300
|
tolerance = user_agent.first_slash
|
348
|
-
|
349
|
-
if
|
301
|
+
matched_ua = ris_match(user_agent, tolerance)
|
302
|
+
if matched_ua.nil?
|
350
303
|
tolerance = 6
|
351
|
-
|
304
|
+
matched_ua = ris_match(user_agent, tolerance)
|
352
305
|
end
|
306
|
+
return matched_ua
|
353
307
|
end
|
354
308
|
|
355
309
|
def matcher_kddi(user_agent)
|
@@ -359,44 +313,47 @@ module WurflDevice
|
|
359
313
|
else
|
360
314
|
tolerance = user_agent.first_slash
|
361
315
|
end
|
362
|
-
|
363
|
-
if
|
364
|
-
|
316
|
+
matched_ua = ris_match(user_agent, tolerance)
|
317
|
+
if matched_ua.nil?
|
318
|
+
matched_ua = 'DO_NOT_MATCH_UP.Browser/6.2'
|
365
319
|
end
|
320
|
+
return matched_ua
|
366
321
|
end
|
367
322
|
|
368
323
|
def matcher_kyocera(user_agent)
|
369
324
|
tolerance = user_agent.first_slash
|
370
|
-
|
325
|
+
return ris_match(user_agent, tolerance)
|
371
326
|
end
|
372
327
|
|
373
328
|
def matcher_lg(user_agent)
|
374
329
|
tolerance = user_agent.index_of_or_length('/', user_agent.index('LG'))
|
375
|
-
|
376
|
-
if
|
330
|
+
matched_ua = ris_match(user_agent, tolerance)
|
331
|
+
if matched_ua.nil?
|
377
332
|
tolerance = 7
|
378
|
-
|
333
|
+
matched_ua = ris_match(user_agent, tolerance)
|
379
334
|
end
|
335
|
+
return matched_ua
|
380
336
|
end
|
381
337
|
|
382
338
|
def matcher_mitsubishi(user_agent)
|
383
339
|
tolerance = user_agent.first_slash
|
384
|
-
|
340
|
+
return ris_match(user_agent, tolerance)
|
385
341
|
end
|
386
342
|
|
387
343
|
def matcher_nec(user_agent)
|
388
344
|
tolerance = user_agent.first_slash
|
389
|
-
|
390
|
-
if
|
345
|
+
matched_ua = ris_match(user_agent, tolerance)
|
346
|
+
if matched_ua.nil?
|
391
347
|
tolerance = 2
|
392
|
-
|
348
|
+
matched_ua = ris_match(user_agent, tolerance)
|
393
349
|
end
|
350
|
+
return matched_ua
|
394
351
|
end
|
395
352
|
|
396
353
|
def matcher_nintendo(user_agent)
|
397
354
|
@device = ld_match(user_agent, tolerance)
|
398
|
-
if
|
399
|
-
|
355
|
+
if matched_ua.nil?
|
356
|
+
matched_ua = case
|
400
357
|
when user_agent.contains('Nintendo Wii')
|
401
358
|
'Opera/9.00 (Nintendo Wii; U; ; 1621; en)'
|
402
359
|
when user_agent.contains('Nintendo DSi')
|
@@ -406,77 +363,79 @@ module WurflDevice
|
|
406
363
|
else
|
407
364
|
'Opera/9.00 (Nintendo Wii; U; ; 1621; en)'
|
408
365
|
end
|
409
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
410
366
|
end
|
367
|
+
return matched_ua
|
411
368
|
end
|
412
369
|
|
413
370
|
def matcher_panasonic(user_agent)
|
414
371
|
tolerance = user_agent.first_slash
|
415
|
-
|
372
|
+
return ris_match(user_agent, tolerance)
|
416
373
|
end
|
417
374
|
|
418
375
|
def matcher_pantech(user_agent)
|
419
376
|
tolerance = 5
|
420
377
|
if !user_agent.starts_with('Pantech')
|
421
378
|
tolerance = user_agent.first_slash
|
422
|
-
|
379
|
+
matched_ua = ris_match(user_agent, tolerance)
|
423
380
|
end
|
424
|
-
|
381
|
+
matched_ua = ris_match(user_agent, tolerance)
|
382
|
+
return matched_ua
|
425
383
|
end
|
426
384
|
|
427
385
|
def matcher_philips(user_agent)
|
428
386
|
tolerance = user_agent.first_slash
|
429
|
-
|
387
|
+
return ris_match(user_agent, tolerance)
|
430
388
|
end
|
431
389
|
|
432
390
|
def matcher_portalmmm(user_agent)
|
433
|
-
|
391
|
+
return WurflDevice::Settings::GENERIC
|
434
392
|
end
|
435
393
|
|
436
394
|
def matcher_qtek(user_agent)
|
437
395
|
tolerance = user_agent.first_slash
|
438
|
-
|
396
|
+
return ris_match(user_agent, tolerance)
|
439
397
|
end
|
440
398
|
|
441
399
|
def matcher_sagem(user_agent)
|
442
400
|
tolerance = user_agent.first_slash
|
443
|
-
|
401
|
+
return ris_match(user_agent, tolerance)
|
444
402
|
end
|
445
403
|
|
446
404
|
def matcher_sharp(user_agent)
|
447
405
|
tolerance = user_agent.first_slash
|
448
|
-
|
406
|
+
return ris_match(user_agent, tolerance)
|
449
407
|
end
|
450
408
|
|
451
409
|
def matcher_siemens(user_agent)
|
452
410
|
tolerance = user_agent.first_slash
|
453
|
-
|
411
|
+
return ris_match(user_agent, tolerance)
|
454
412
|
end
|
455
413
|
|
456
414
|
def matcher_spv(user_agent)
|
457
415
|
pos = user_agent.index(';')
|
458
416
|
tolerance = pos || user_agent.index('SPV')
|
459
|
-
|
417
|
+
return ris_match(user_agent, tolerance)
|
460
418
|
end
|
461
419
|
|
462
420
|
def matcher_toshiba(user_agent)
|
463
421
|
tolerance = user_agent.first_slash
|
464
|
-
|
422
|
+
return ris_match(user_agent, tolerance)
|
465
423
|
end
|
466
424
|
|
467
425
|
def matcher_vodafone(user_agent)
|
468
426
|
tolerance = user_agent.first_slash
|
469
|
-
|
470
|
-
if
|
471
|
-
|
427
|
+
matched_ua = ris_match(user_agent, tolerance)
|
428
|
+
if matched_ua.nil?
|
429
|
+
matched_ua = ld_match(user_agent)
|
472
430
|
end
|
431
|
+
return matched_ua
|
473
432
|
end
|
474
433
|
|
475
434
|
# mobile browsers
|
476
435
|
def matcher_android(user_agent)
|
477
|
-
|
436
|
+
matched_ua = 'DO_NOT_MATCH_GENERIC_ANDROID'
|
478
437
|
if user_agent.contains('Froyo')
|
479
|
-
|
438
|
+
matched_ua = 'DO_NOT_MATCH_ANDROID_2_2'
|
480
439
|
elsif user_agent =~ /#Android[\s\/](\d).(\d)#/
|
481
440
|
version = "generic_android_ver#{$1}_#{$2}"
|
482
441
|
version = 'generic_android_ver2' if version == 'generic_android_ver2_0'
|
@@ -487,40 +446,42 @@ module WurflDevice
|
|
487
446
|
'generic_android_ver2_1' => 'DO_NOT_MATCH_GENERIC_ANDROID_2_1',
|
488
447
|
'generic_android_ver2_2' => 'DO_NOT_MATCH_ANDROID_2_2',
|
489
448
|
}
|
490
|
-
|
449
|
+
matched_ua = android_uas[version] if android_uas.has_key?(version)
|
491
450
|
end
|
492
|
-
|
451
|
+
return matched_ua
|
493
452
|
end
|
494
453
|
|
495
454
|
def matcher_operamini(user_agent)
|
496
455
|
tolerance = user_agent.first_slash
|
497
|
-
|
498
|
-
if
|
499
|
-
|
456
|
+
matched_ua = ris_match(user_agent, tolerance)
|
457
|
+
if matched_ua.nil?
|
458
|
+
matched_ua = 'DO_NOT_MATCH_GENERIC_OPERA_MINI_VERSION_1';
|
500
459
|
if user_agent =~ /#Opera Mini\/([1-5])#/
|
501
|
-
|
460
|
+
matched_ua = "DO_NOT_MATCH_BROWSER_OPERA_MINI_#{$1}_0"
|
502
461
|
elsif user_agent.contains('Opera Mobi')
|
503
|
-
|
462
|
+
matched_ua = 'DO_NOT_MATCH_GENERIC_OPERA_MINI_VERSION_4'
|
504
463
|
end
|
505
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
506
464
|
end
|
465
|
+
return matched_ua
|
507
466
|
end
|
508
467
|
|
509
468
|
def matcher_windowsce(user_agent)
|
510
469
|
tolerance = 3
|
511
|
-
|
512
|
-
if
|
513
|
-
|
470
|
+
matched_ua = ld_match(user_agent, tolerance)
|
471
|
+
if matched_ua.nil?
|
472
|
+
matched_ua = 'DO_NOT_MATCH_REMOVE_GENERIC_MS_MOBILE_BROWSER_VER1'
|
514
473
|
end
|
474
|
+
return matched_ua
|
515
475
|
end
|
516
476
|
|
517
477
|
# robots
|
518
478
|
def matcher_bot(user_agent)
|
519
479
|
tolerance = user_agent.first_slash
|
520
|
-
|
521
|
-
if
|
522
|
-
|
480
|
+
matched_ua = ris_match(user_agent, tolerance)
|
481
|
+
if matched_ua.nil?
|
482
|
+
matched_ua = 'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
|
523
483
|
end
|
484
|
+
return matched_ua
|
524
485
|
end
|
525
486
|
|
526
487
|
# desktop browsers
|
@@ -528,7 +489,7 @@ module WurflDevice
|
|
528
489
|
if user_agent =~ /^Mozilla\/4\.0 \(compatible; MSIE (\d)\.(\d);/
|
529
490
|
version = $1.to_i
|
530
491
|
version_sub = $2.to_i
|
531
|
-
|
492
|
+
matched_ua = case
|
532
493
|
when version == 7
|
533
494
|
'Mozilla/4.0 (compatible; MSIE 7.0;'
|
534
495
|
when version == 8
|
@@ -542,26 +503,26 @@ module WurflDevice
|
|
542
503
|
else
|
543
504
|
'msie'
|
544
505
|
end
|
545
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
546
506
|
else
|
547
507
|
user_agent.sub!(/( \.NET CLR [\d\.]+;?| Media Center PC [\d\.]+;?| OfficeLive[a-zA-Z0-9\.\d]+;?| InfoPath[\.\d]+;?)/, '')
|
548
508
|
tolerance = user_agent.first_slash
|
549
|
-
|
509
|
+
matched_ua = ris_match(user_agent, tolerance)
|
550
510
|
end
|
551
|
-
if
|
511
|
+
if matched_ua.nil?
|
552
512
|
if user_agent.contains(['SLCC1', 'Media Center PC', '.NET CLR', 'OfficeLiveConnector'])
|
553
|
-
|
513
|
+
matched_ua'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
|
554
514
|
else
|
555
|
-
|
515
|
+
matched_ua = WurflDevice::Settings::GENERIC
|
556
516
|
end
|
557
517
|
end
|
518
|
+
return matched_ua
|
558
519
|
end
|
559
520
|
|
560
521
|
def matcher_firefox(user_agent)
|
561
522
|
if user_agent =~ /Firefox\/(\d)\.(\d)/
|
562
523
|
version = $1.to_i
|
563
524
|
version_sub = $2.to_i
|
564
|
-
|
525
|
+
matched_ua = case
|
565
526
|
when version == 3
|
566
527
|
version_sub == 5 ? 'Firefox/3.5' : 'Firefox/3.0'
|
567
528
|
when version == 2
|
@@ -571,28 +532,29 @@ module WurflDevice
|
|
571
532
|
else
|
572
533
|
nil
|
573
534
|
end
|
574
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true) unless device_ua.nil?
|
575
535
|
else
|
576
536
|
tolerance = 5
|
577
|
-
|
537
|
+
matched_ua = ld_match(user_agent, tolerance)
|
578
538
|
end
|
539
|
+
return matched_ua
|
579
540
|
end
|
580
541
|
|
581
542
|
def matcher_chrome(user_agent)
|
582
543
|
tolerance = user_agent.index_of_or_length('/', user_agent.index('Chrome'))
|
583
|
-
|
584
|
-
if
|
585
|
-
|
544
|
+
matched_ua = ris_match(user_agent, tolerance)
|
545
|
+
if matched_ua.nil?
|
546
|
+
matched_ua = 'Chrome'
|
586
547
|
end
|
548
|
+
return matched_ua
|
587
549
|
end
|
588
550
|
|
589
551
|
def matcher_konqueror(user_agent)
|
590
552
|
tolerance = user_agent.first_slash
|
591
|
-
|
553
|
+
return ris_match(user_agent, tolerance)
|
592
554
|
end
|
593
555
|
|
594
556
|
def matcher_opera(user_agent)
|
595
|
-
|
557
|
+
matched_ua = case
|
596
558
|
when user_agent.contains('Opera/10')
|
597
559
|
'Opera/10'
|
598
560
|
when user_agent.contains('Opera/9')
|
@@ -604,30 +566,30 @@ module WurflDevice
|
|
604
566
|
else
|
605
567
|
nil
|
606
568
|
end
|
607
|
-
|
608
|
-
if @device.nil?
|
569
|
+
if matched_ua.nil?
|
609
570
|
tolerance = 5
|
610
|
-
|
571
|
+
matched_ua = ld_match(user_agent, tolerance)
|
611
572
|
end
|
612
|
-
|
573
|
+
matched_ua = 'Opera' if matched_ua.nil?
|
574
|
+
return matched_ua
|
613
575
|
end
|
614
576
|
|
615
577
|
def matcher_safari(user_agent)
|
616
578
|
tolerance = user_agent.first_slash
|
617
|
-
|
618
|
-
if
|
619
|
-
|
579
|
+
matched_ua = ris_match(user_agent, tolerance)
|
580
|
+
if matched_ua.nil?
|
581
|
+
matched_ua = case
|
620
582
|
when user_agent.contains('Macintosh') || user_agent.contains('Windows')
|
621
583
|
'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
|
622
584
|
else
|
623
|
-
WurflDevice::
|
585
|
+
WurflDevice::Settings::GENERIC
|
624
586
|
end
|
625
|
-
@device = WurflDevice.get_device_from_ua_cache(device_ua, true)
|
626
587
|
end
|
588
|
+
return matched_ua
|
627
589
|
end
|
628
590
|
|
629
591
|
def matcher_aol(user_agent)
|
630
|
-
|
592
|
+
return 'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
|
631
593
|
end
|
632
594
|
end
|
633
595
|
end
|