brauser 3.2.2 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis-gemfile +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -4
- data/README.md +1 -0
- data/brauser.gemspec +2 -1
- data/doc/Brauser.html +3 -3
- data/doc/Brauser/Browser.html +252 -252
- data/doc/Brauser/BrowserMethods.html +3 -3
- data/doc/Brauser/BrowserMethods/Attributes.html +20 -20
- data/doc/Brauser/BrowserMethods/General.html +3 -3
- data/doc/Brauser/BrowserMethods/General/ClassMethods.html +27 -27
- data/doc/Brauser/BrowserMethods/Parsing.html +18 -18
- data/doc/Brauser/BrowserMethods/PartialQuerying.html +40 -38
- data/doc/Brauser/BrowserMethods/Querying.html +126 -21
- data/doc/Brauser/BrowserMethods/Register.html +3 -3
- data/doc/Brauser/BrowserMethods/Register/ClassMethods.html +5 -5
- data/doc/Brauser/Chainers.html +14 -13
- data/doc/Brauser/Definition.html +33 -23
- data/doc/Brauser/Hooks.html +3 -3
- data/doc/Brauser/Hooks/RubyOnRails.html +3 -3
- data/doc/Brauser/Queries.html +20 -19
- data/doc/Brauser/Query.html +15 -15
- data/doc/Brauser/Version.html +4 -4
- data/doc/_index.html +4 -4
- data/doc/css/style.css +1 -1
- data/doc/file.README.html +5 -4
- data/doc/frames.html +5 -7
- data/doc/index.html +5 -4
- data/doc/js/app.js +7 -2
- data/doc/method_list.html +17 -11
- data/doc/top-level-namespace.html +3 -3
- data/lib/brauser/browser.rb +59 -27
- data/lib/brauser/definition.rb +4 -3
- data/lib/brauser/query.rb +4 -2
- data/lib/brauser/version.rb +1 -1
- data/spec/brauser/browser_spec.rb +16 -0
- data/spec/supported.yml +3 -0
- metadata +9 -5
data/doc/Brauser/Version.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Brauser::Version
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7
|
9
|
+
— Documentation by YARD 0.8.7.3
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -149,7 +149,7 @@
|
|
149
149
|
|
150
150
|
</div>
|
151
151
|
</dt>
|
152
|
-
<dd><pre class="code"><span class='int'>
|
152
|
+
<dd><pre class="code"><span class='int'>3</span></pre></dd>
|
153
153
|
|
154
154
|
<dt id="STRING-constant" class="">STRING =
|
155
155
|
<div class="docstring">
|
@@ -180,9 +180,9 @@
|
|
180
180
|
</div>
|
181
181
|
|
182
182
|
<div id="footer">
|
183
|
-
Generated on
|
183
|
+
Generated on Sat Nov 16 10:49:21 2013 by
|
184
184
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
185
|
-
0.8.7 (ruby-2.0.0).
|
185
|
+
0.8.7.3 (ruby-2.0.0).
|
186
186
|
</div>
|
187
187
|
|
188
188
|
</body>
|
data/doc/_index.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<head>
|
5
5
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
6
|
<title>
|
7
|
-
Documentation by YARD 0.8.7
|
7
|
+
Documentation by YARD 0.8.7.3
|
8
8
|
|
9
9
|
</title>
|
10
10
|
|
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
<iframe id="search_frame"></iframe>
|
58
58
|
|
59
|
-
<div id="content"><h1 class="noborder title">Documentation by YARD 0.8.7</h1>
|
59
|
+
<div id="content"><h1 class="noborder title">Documentation by YARD 0.8.7.3</h1>
|
60
60
|
<div id="listing">
|
61
61
|
<h1 class="alphaindex">Alphabetic Index</h1>
|
62
62
|
|
@@ -295,9 +295,9 @@
|
|
295
295
|
</div>
|
296
296
|
|
297
297
|
<div id="footer">
|
298
|
-
Generated on
|
298
|
+
Generated on Sat Nov 16 10:49:21 2013 by
|
299
299
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
300
|
-
0.8.7 (ruby-2.0.0).
|
300
|
+
0.8.7.3 (ruby-2.0.0).
|
301
301
|
</div>
|
302
302
|
|
303
303
|
</body>
|
data/doc/css/style.css
CHANGED
@@ -324,9 +324,9 @@ pre.code .dot + pre.code .id,
|
|
324
324
|
pre.code .rubyid_to_i pre.code .rubyid_each { color: #0085FF; }
|
325
325
|
pre.code .comment { color: #0066FF; }
|
326
326
|
pre.code .const, pre.code .constant { color: #585CF6; }
|
327
|
+
pre.code .label,
|
327
328
|
pre.code .symbol { color: #C5060B; }
|
328
329
|
pre.code .kw,
|
329
|
-
pre.code .label,
|
330
330
|
pre.code .rubyid_require,
|
331
331
|
pre.code .rubyid_extend,
|
332
332
|
pre.code .rubyid_include { color: #0000FF; }
|
data/doc/file.README.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7
|
9
|
+
— Documentation by YARD 0.8.7.3
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -67,7 +67,8 @@
|
|
67
67
|
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status" /></a>
|
68
68
|
<a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status" /></a>
|
69
69
|
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate" /></a>
|
70
|
-
<a href="https://coveralls.io/r/ShogunPanda/brauser"><img src="https://coveralls.io/repos/ShogunPanda/brauser/badge.png" alt="Coverage Status" /></a
|
70
|
+
<a href="https://coveralls.io/r/ShogunPanda/brauser"><img src="https://coveralls.io/repos/ShogunPanda/brauser/badge.png" alt="Coverage Status" /></a>
|
71
|
+
<a href="https://bitdeli.com/free" title="Bitdeli Badge"><img src="https://d2weczhvl823v0.cloudfront.net/ShogunPanda/brauser/trend.png" alt="Bitdeli Trend" /></a></p>
|
71
72
|
|
72
73
|
<p>A framework agnostic browser detection and querying helper.</p>
|
73
74
|
|
@@ -269,9 +270,9 @@ Brauser::Browsers.add(:languages, ::Brauser::Definition.new(:it, "Italian"))
|
|
269
270
|
</div></div>
|
270
271
|
|
271
272
|
<div id="footer">
|
272
|
-
Generated on
|
273
|
+
Generated on Sat Nov 16 10:49:21 2013 by
|
273
274
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
274
|
-
0.8.7 (ruby-2.0.0).
|
275
|
+
0.8.7.3 (ruby-2.0.0).
|
275
276
|
</div>
|
276
277
|
|
277
278
|
</body>
|
data/doc/frames.html
CHANGED
@@ -4,18 +4,16 @@
|
|
4
4
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
5
|
<head>
|
6
6
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
-
<title>Documentation by YARD 0.8.7</title>
|
7
|
+
<title>Documentation by YARD 0.8.7.3</title>
|
8
8
|
</head>
|
9
9
|
<script type="text/javascript" charset="utf-8">
|
10
10
|
window.onload = function() {
|
11
|
-
var match = window.location.hash.match(/^#!(.+)/);
|
12
|
-
var name = 'index.html';
|
13
|
-
|
14
|
-
name = unescape(match[1]);
|
15
|
-
}
|
11
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
12
|
+
var name = match ? match[1] : 'index.html';
|
13
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
16
14
|
document.writeln('<frameset cols="20%,*">' +
|
17
15
|
'<frame name="list" src="class_list.html" />' +
|
18
|
-
'<frame name="main" src="' + name + '" />' +
|
16
|
+
'<frame name="main" src="' + escape(name) + '" />' +
|
19
17
|
'</frameset>');
|
20
18
|
}
|
21
19
|
</script>
|
data/doc/index.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7
|
9
|
+
— Documentation by YARD 0.8.7.3
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -67,7 +67,8 @@
|
|
67
67
|
<a href="https://gemnasium.com/ShogunPanda/brauser"><img src="https://gemnasium.com/ShogunPanda/brauser.png?travis" alt="Dependency Status" /></a>
|
68
68
|
<a href="http://travis-ci.org/ShogunPanda/brauser"><img src="https://secure.travis-ci.org/ShogunPanda/brauser.png?branch=master" alt="Build Status" /></a>
|
69
69
|
<a href="https://codeclimate.com/github/ShogunPanda/brauser"><img src="https://codeclimate.com/github/ShogunPanda/brauser.png" alt="Code Climate" /></a>
|
70
|
-
<a href="https://coveralls.io/r/ShogunPanda/brauser"><img src="https://coveralls.io/repos/ShogunPanda/brauser/badge.png" alt="Coverage Status" /></a
|
70
|
+
<a href="https://coveralls.io/r/ShogunPanda/brauser"><img src="https://coveralls.io/repos/ShogunPanda/brauser/badge.png" alt="Coverage Status" /></a>
|
71
|
+
<a href="https://bitdeli.com/free" title="Bitdeli Badge"><img src="https://d2weczhvl823v0.cloudfront.net/ShogunPanda/brauser/trend.png" alt="Bitdeli Trend" /></a></p>
|
71
72
|
|
72
73
|
<p>A framework agnostic browser detection and querying helper.</p>
|
73
74
|
|
@@ -269,9 +270,9 @@ Brauser::Browsers.add(:languages, ::Brauser::Definition.new(:it, "Italian"))
|
|
269
270
|
</div></div>
|
270
271
|
|
271
272
|
<div id="footer">
|
272
|
-
Generated on
|
273
|
+
Generated on Sat Nov 16 10:49:21 2013 by
|
273
274
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
274
|
-
0.8.7 (ruby-2.0.0).
|
275
|
+
0.8.7.3 (ruby-2.0.0).
|
275
276
|
</div>
|
276
277
|
|
277
278
|
</body>
|
data/doc/js/app.js
CHANGED
@@ -78,7 +78,12 @@ function framesInit() {
|
|
78
78
|
if (hasFrames) {
|
79
79
|
document.body.className = 'frames';
|
80
80
|
$('#menu .noframes a').attr('href', document.location);
|
81
|
-
|
81
|
+
try {
|
82
|
+
window.top.document.title = $('html head title').text();
|
83
|
+
} catch(error) {
|
84
|
+
// some browsers will not allow this when serving from file://
|
85
|
+
// but we don't want to stop the world.
|
86
|
+
}
|
82
87
|
}
|
83
88
|
else {
|
84
89
|
$('#menu .noframes a').text('frames').attr('href', framesUrl);
|
@@ -211,4 +216,4 @@ $(linkSummaries);
|
|
211
216
|
$(keyboardShortcuts);
|
212
217
|
$(summaryToggle);
|
213
218
|
$(fixOutsideWorldLinks);
|
214
|
-
$(generateTOC);
|
219
|
+
$(generateTOC);
|
data/doc/method_list.html
CHANGED
@@ -228,14 +228,14 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
<li class="r1 ">
|
231
|
-
<span class='object_link'><a href="Brauser/
|
232
|
-
<small>Brauser::
|
231
|
+
<span class='object_link'><a href="Brauser/BrowserMethods/Querying.html#on%3F-instance_method" title="Brauser::BrowserMethods::Querying#on? (method)">#on?</a></span>
|
232
|
+
<small>Brauser::BrowserMethods::Querying</small>
|
233
233
|
</li>
|
234
234
|
|
235
235
|
|
236
236
|
<li class="r2 ">
|
237
|
-
<span class='object_link'><a href="Brauser/
|
238
|
-
<small>Brauser::
|
237
|
+
<span class='object_link'><a href="Brauser/Queries.html#on%3F-instance_method" title="Brauser::Queries#on? (method)">#on?</a></span>
|
238
|
+
<small>Brauser::Queries</small>
|
239
239
|
</li>
|
240
240
|
|
241
241
|
|
@@ -294,48 +294,54 @@
|
|
294
294
|
|
295
295
|
|
296
296
|
<li class="r2 ">
|
297
|
+
<span class='object_link'><a href="Brauser/BrowserMethods/Querying.html#supported%3F-instance_method" title="Brauser::BrowserMethods::Querying#supported? (method)">#supported?</a></span>
|
298
|
+
<small>Brauser::BrowserMethods::Querying</small>
|
299
|
+
</li>
|
300
|
+
|
301
|
+
|
302
|
+
<li class="r1 ">
|
297
303
|
<span class='object_link'><a href="Brauser/Definition.html#tag-instance_method" title="Brauser::Definition#tag (method)">#tag</a></span>
|
298
304
|
<small>Brauser::Definition</small>
|
299
305
|
</li>
|
300
306
|
|
301
307
|
|
302
|
-
<li class="
|
308
|
+
<li class="r2 ">
|
303
309
|
<span class='object_link'><a href="Brauser/Query.html#target-instance_method" title="Brauser::Query#target (method)">#target</a></span>
|
304
310
|
<small>Brauser::Query</small>
|
305
311
|
</li>
|
306
312
|
|
307
313
|
|
308
|
-
<li class="
|
314
|
+
<li class="r1 ">
|
309
315
|
<span class='object_link'><a href="Brauser/Browser.html#to_s-instance_method" title="Brauser::Browser#to_s (method)">#to_s</a></span>
|
310
316
|
<small>Brauser::Browser</small>
|
311
317
|
</li>
|
312
318
|
|
313
319
|
|
314
|
-
<li class="
|
320
|
+
<li class="r2 ">
|
315
321
|
<span class='object_link'><a href="Brauser/BrowserMethods/PartialQuerying.html#v-instance_method" title="Brauser::BrowserMethods::PartialQuerying#v (method)">#v</a></span>
|
316
322
|
<small>Brauser::BrowserMethods::PartialQuerying</small>
|
317
323
|
</li>
|
318
324
|
|
319
325
|
|
320
|
-
<li class="
|
326
|
+
<li class="r1 ">
|
321
327
|
<span class='object_link'><a href="Brauser/Chainers.html#v-instance_method" title="Brauser::Chainers#v (method)">#v</a></span>
|
322
328
|
<small>Brauser::Chainers</small>
|
323
329
|
</li>
|
324
330
|
|
325
331
|
|
326
|
-
<li class="
|
332
|
+
<li class="r2 ">
|
327
333
|
<span class='object_link'><a href="Brauser/BrowserMethods/Querying.html#v%3F-instance_method" title="Brauser::BrowserMethods::Querying#v? (method)">#v?</a></span>
|
328
334
|
<small>Brauser::BrowserMethods::Querying</small>
|
329
335
|
</li>
|
330
336
|
|
331
337
|
|
332
|
-
<li class="
|
338
|
+
<li class="r1 ">
|
333
339
|
<span class='object_link'><a href="Brauser/Queries.html#v%3F-instance_method" title="Brauser::Queries#v? (method)">#v?</a></span>
|
334
340
|
<small>Brauser::Queries</small>
|
335
341
|
</li>
|
336
342
|
|
337
343
|
|
338
|
-
<li class="
|
344
|
+
<li class="r2 ">
|
339
345
|
<span class='object_link'><a href="Brauser/Browser.html#version-instance_method" title="Brauser::Browser#version (method)">#version</a></span>
|
340
346
|
<small>Brauser::Browser</small>
|
341
347
|
</li>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7
|
9
|
+
— Documentation by YARD 0.8.7.3
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -103,9 +103,9 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sat Nov 16 10:49:21 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
-
0.8.7 (ruby-2.0.0).
|
108
|
+
0.8.7.3 (ruby-2.0.0).
|
109
109
|
</div>
|
110
110
|
|
111
111
|
</body>
|
data/lib/brauser/browser.rb
CHANGED
@@ -62,7 +62,7 @@ module Brauser
|
|
62
62
|
[:linux, "Linux", /linux/i],
|
63
63
|
[:osx, "Apple MacOS X", /mac|macintosh|mac os x/i],
|
64
64
|
[:windows, "Microsoft Windows", /windows/i]
|
65
|
-
].
|
65
|
+
].map { |platform| ::Brauser::Definition.send(:new, *platform) })
|
66
66
|
end
|
67
67
|
|
68
68
|
# Adds a default list of languages that can be recognized.
|
@@ -183,7 +183,7 @@ module Brauser
|
|
183
183
|
"xh" => "Xshosa",
|
184
184
|
"ji" => "Yiddish",
|
185
185
|
"zu" => "Zulu"
|
186
|
-
}.
|
186
|
+
}.map { |code, name| ::Brauser::Definition.new(code, name, code) })
|
187
187
|
end
|
188
188
|
|
189
189
|
private
|
@@ -195,8 +195,8 @@ module Brauser
|
|
195
195
|
[:chrome, "Google Chrome", /((chrome)|(chromium))/i, /(.+Chrom[a-z]+\/)([a-z0-9.]+)/i],
|
196
196
|
[:netscape, "Netscape Navigator", /(netscape|navigator)\//i, /((Netscape|Navigator)\/)([a-z0-9.]+)/i],
|
197
197
|
[:firefox, "Mozilla Firefox", /firefox/i, /(.+Firefox\/)([a-z0-9.]+)/i],
|
198
|
-
[:safari, "Apple Safari", Proc.new{ |_, agent| agent
|
199
|
-
].
|
198
|
+
[:safari, "Apple Safari", Proc.new{ |_, agent| disambiguate_browser(agent, /safari/i, /((chrome)|(chromium))/i) }, /(.+Version\/)([a-z0-9.]+)/i],
|
199
|
+
].map { |browser| ::Brauser::Definition.send(:new, *browser) })
|
200
200
|
end
|
201
201
|
|
202
202
|
# Registers definitions for MSIE browsers.
|
@@ -209,8 +209,8 @@ module Brauser
|
|
209
209
|
version[0] = version[0].to_integer + 4
|
210
210
|
version.join(".")
|
211
211
|
}],
|
212
|
-
[:msie, "Microsoft Internet Explorer", Proc.new{ |_, agent| agent
|
213
|
-
].
|
212
|
+
[:msie, "Microsoft Internet Explorer", Proc.new{ |_, agent| disambiguate_browser(agent, /msie/i, /opera/i) }, /(.+MSIE )([a-z0-9.]+)/i],
|
213
|
+
].map { |browser| ::Brauser::Definition.send(:new, *browser) })
|
214
214
|
end
|
215
215
|
|
216
216
|
# Registers the least common desktop browsers.
|
@@ -221,7 +221,7 @@ module Brauser
|
|
221
221
|
[:quicktime, "Apple QuickTime", /quicktime/i, /(.+((QuickTime\/)|(qtver=)))([a-z0-9.]+)/i],
|
222
222
|
[:webkit, "WebKit Browser", /webkit/i, /(.+WebKit\/)([a-z0-9.]+)/i],
|
223
223
|
[:gecko, "Gecko Browser", /gecko/i, /(.+rv:|Gecko\/)([a-z0-9.]+)/i],
|
224
|
-
].
|
224
|
+
].map { |browser| ::Brauser::Definition.send(:new, *browser) })
|
225
225
|
end
|
226
226
|
|
227
227
|
# Register the most common mobile and console browsers.
|
@@ -232,8 +232,8 @@ module Brauser
|
|
232
232
|
[:coremedia, "Apple CoreMedia", /coremedia/i, /.+CoreMedia v([a-z0-9.]+)/i],
|
233
233
|
|
234
234
|
[:opera_mobile, "Opera Mobile", /opera mobi/i, /.+Opera Mobi.+((.+Opera )|(Version\/))([a-z0-9.]+)/i],
|
235
|
-
[:opera, "Opera", /opera/i, Proc.new{ |_,
|
236
|
-
version = ((
|
235
|
+
[:opera, "Opera", /opera/i, Proc.new{ |_, a|
|
236
|
+
version = ((a !~ /wii/i) ? /((.+Opera )|(Version\/))(?<version>[a-z0-9.]+)/i : /(.+Nintendo Wii; U; ; )(?<version>[a-z0-9.]+)/i).match(a)
|
237
237
|
version ? version["version"] : nil
|
238
238
|
}],
|
239
239
|
|
@@ -250,7 +250,17 @@ module Brauser
|
|
250
250
|
[:ipad, "Apple iPad", /ipad/i, /(.+Version\/)([a-z0-9.]+)/i],
|
251
251
|
|
252
252
|
[:mobile, "Other Mobile Browser", /(mobile|symbian|midp|windows ce)/i, /.+\/([a-z0-9.]+)/i],
|
253
|
-
].
|
253
|
+
].map { |browser| ::Brauser::Definition.send(:new, *browser) })
|
254
|
+
end
|
255
|
+
|
256
|
+
# Recognizes a browser disambiguating against another.
|
257
|
+
#
|
258
|
+
# @param agent [String] The agent to match.
|
259
|
+
# @param positive_matcher [Regexp] The expression to match.
|
260
|
+
# @param positive_matcher [Regexp] The expression NOT to match.
|
261
|
+
# @return [Boolean] `true` if matching succeeded, `false otherwise`.
|
262
|
+
def disambiguate_browser(agent, positive_matcher, negative_matcher)
|
263
|
+
agent =~ positive_matcher && agent !~ negative_matcher
|
254
264
|
end
|
255
265
|
end
|
256
266
|
end
|
@@ -355,7 +365,7 @@ module Brauser
|
|
355
365
|
# @return [String] A human-readable browser name.
|
356
366
|
def readable_name
|
357
367
|
parse_agent(@agent) if !@name
|
358
|
-
::Brauser::Browser.browsers
|
368
|
+
::Brauser::Browser.browsers.fetch(@name).label rescue "Unknown Browser"
|
359
369
|
end
|
360
370
|
|
361
371
|
# Gets a human-readable platform name.
|
@@ -397,10 +407,7 @@ module Brauser
|
|
397
407
|
# @return [String|Array|nil] The browser name(s) or `nil`, if it was set to be skipped.
|
398
408
|
def stringify_name(name, &block)
|
399
409
|
if name then
|
400
|
-
name =
|
401
|
-
self.parse_agent(@agent) if !@name
|
402
|
-
block ||= Proc.new {|n, *| n == :msie_compatibility ? [:msie_compatibility, :msie] : n }
|
403
|
-
|
410
|
+
name, block = prepare_name_stringification(name, block)
|
404
411
|
names = block.call(@name, @version, @platform).ensure_array {|n| "#{name}#{n}" }
|
405
412
|
names.length > 1 ? names : names.first
|
406
413
|
else
|
@@ -408,6 +415,16 @@ module Brauser
|
|
408
415
|
end
|
409
416
|
end
|
410
417
|
|
418
|
+
# Prepare a name stringification
|
419
|
+
#
|
420
|
+
# @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
|
421
|
+
# @param block [Proc] A block to translate browser name.
|
422
|
+
# @return [Array] A name and a translator ready to use.
|
423
|
+
def prepare_name_stringification(name, block)
|
424
|
+
self.parse_agent(@agent) if !@name
|
425
|
+
[(name.is_a?(TrueClass) ? "" : name), block || Proc.new {|n, *| n == :msie_compatibility ? [:msie_compatibility, :msie] : n }]
|
426
|
+
end
|
427
|
+
|
411
428
|
# Stringifies a browser version.
|
412
429
|
#
|
413
430
|
# @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
|
@@ -416,7 +433,7 @@ module Brauser
|
|
416
433
|
version = "version-" if version.is_a?(TrueClass)
|
417
434
|
tokens = @version.split(".")
|
418
435
|
|
419
|
-
!version ? nil : tokens.
|
436
|
+
!version ? nil : tokens.reduce([version + tokens.shift]) {|prev, current|
|
420
437
|
prev + [prev.last + "_" + current]
|
421
438
|
}.flatten
|
422
439
|
end
|
@@ -442,7 +459,7 @@ module Brauser
|
|
442
459
|
# @param accept_language [String] The Accept-Language header.
|
443
460
|
# @return [Array] The list of accepted languages.
|
444
461
|
def parse_accept_language(accept_language = nil)
|
445
|
-
accept_language.ensure_string.gsub(/;q=[\d.]+/, "").split(",").
|
462
|
+
accept_language.ensure_string.gsub(/;q=[\d.]+/, "").split(",").map {|l| l.downcase.strip }.select{|l| l.present? }
|
446
463
|
end
|
447
464
|
|
448
465
|
private
|
@@ -503,7 +520,8 @@ module Brauser
|
|
503
520
|
# @see #on?
|
504
521
|
#
|
505
522
|
# @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
|
506
|
-
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
523
|
+
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
524
|
+
# in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
|
507
525
|
# @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
|
508
526
|
# @return [Query] A query which can evaluated for concatenation or result.
|
509
527
|
def is(names = [], versions = {}, platforms = [])
|
@@ -522,7 +540,8 @@ module Brauser
|
|
522
540
|
|
523
541
|
# Checks if the browser is a specific version.
|
524
542
|
#
|
525
|
-
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
543
|
+
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
544
|
+
# in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
|
526
545
|
# @return [Query] A query which can evaluated for concatenation or result.
|
527
546
|
def v(versions = {})
|
528
547
|
parse_agent(@agent) if !@version
|
@@ -576,10 +595,11 @@ module Brauser
|
|
576
595
|
|
577
596
|
# Parses a version query.
|
578
597
|
#
|
579
|
-
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match
|
598
|
+
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match
|
599
|
+
# against, in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
|
580
600
|
# @return [Hash] The hash representation of the query.
|
581
601
|
def parse_versions_query(versions)
|
582
|
-
versions.is_a?(::Hash) ? versions : versions.ensure_string.split(/\s*&&\s*/).
|
602
|
+
versions.is_a?(::Hash) ? versions : versions.ensure_string.split(/\s*&&\s*/).reduce({}) do |prev, token|
|
583
603
|
operator, version = parse_versions_query_component(token)
|
584
604
|
prev[operator] = version if operator.present? && version.present?
|
585
605
|
prev
|
@@ -591,7 +611,7 @@ module Brauser
|
|
591
611
|
# @param token [String] The token to parse.
|
592
612
|
# @return [Array] An operator and an argument.
|
593
613
|
def parse_versions_query_component(token)
|
594
|
-
operator, version = token.strip.split(/\s+/, 2).
|
614
|
+
operator, version = token.strip.split(/\s+/, 2).map(&:strip)
|
595
615
|
[{"<" => :lt, "<=" => :lte, "=" => :eq, "==" => :eq, ">" => :gt, ">=" => :gte}.fetch(operator, nil), version]
|
596
616
|
end
|
597
617
|
end
|
@@ -604,7 +624,8 @@ module Brauser
|
|
604
624
|
# @see #on?
|
605
625
|
#
|
606
626
|
# @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
|
607
|
-
# @param versions [Hash] An hash with specific version to match against. Need to be in form `{:operator => version}`, where operator
|
627
|
+
# @param versions [Hash] An hash with specific version to match against. Need to be in form `{:operator => version}`, where operator
|
628
|
+
# is one of `:lt, :lte, :eq, :gt, :gte`.
|
608
629
|
# @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
|
609
630
|
# @return [Boolean] `true` if current browser matches, `false` otherwise.
|
610
631
|
def is?(names = [], versions = {}, platforms = [])
|
@@ -613,7 +634,8 @@ module Brauser
|
|
613
634
|
|
614
635
|
# Checks if the browser is a specific version.
|
615
636
|
#
|
616
|
-
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
637
|
+
# @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
|
638
|
+
# in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
|
617
639
|
# @return [Boolean] `true` if current browser matches, `false` otherwise.
|
618
640
|
def v?(versions = {})
|
619
641
|
v(versions).result
|
@@ -634,6 +656,16 @@ module Brauser
|
|
634
656
|
def accepts?(langs = [])
|
635
657
|
accepts(langs).result
|
636
658
|
end
|
659
|
+
|
660
|
+
# Check if the browser is supported.
|
661
|
+
#
|
662
|
+
# @param supported [Hash|String] A map of engines and minimum supported major version, or a path to YAML file containing the map.
|
663
|
+
# @return [Boolean] `true` if current browser is supported, `false` otherwise.
|
664
|
+
def supported?(supported)
|
665
|
+
supported = YAML.load_file(supported).symbolize_keys if supported.is_a?(String)
|
666
|
+
minimum = supported[name]
|
667
|
+
(minimum && v?(gte: minimum)).to_boolean
|
668
|
+
end
|
637
669
|
end
|
638
670
|
end
|
639
671
|
|
@@ -728,7 +760,7 @@ module Brauser
|
|
728
760
|
# @param query [String] The query to issue. Use `__` to separate query and `_` in place of `.` in the version.
|
729
761
|
# @return [Array] And array of `[method, arguments]` entries.
|
730
762
|
def parse_query(query)
|
731
|
-
query.gsub(/\?$/, "").gsub(/(_(v|on|is))/, " \\2").split(" ").
|
763
|
+
query.gsub(/\?$/, "").gsub(/(_(v|on|is))/, " \\2").split(" ").map do |part|
|
732
764
|
parse_query_part(part)
|
733
765
|
end
|
734
766
|
end
|
@@ -763,7 +795,7 @@ module Brauser
|
|
763
795
|
[/_?and_?/, " && "], # Parse &&
|
764
796
|
["_", "."], # Dot notation
|
765
797
|
[/\s+/, " "]
|
766
|
-
].
|
798
|
+
].reduce(version) { |current, parse| current.gsub(parse[0], parse[1])}.strip
|
767
799
|
end
|
768
800
|
|
769
801
|
# Executes a parsed query
|
@@ -771,7 +803,7 @@ module Brauser
|
|
771
803
|
# @param query [Array] And array of `[method, arguments]` entries.
|
772
804
|
# @return [Brauser::Query] The result of the query.
|
773
805
|
def execute_query(query)
|
774
|
-
query.
|
806
|
+
query.reduce(Brauser::Query.new(self, true)) { |rv, call|
|
775
807
|
break if !rv.result
|
776
808
|
rv.send(call[0], *call[1])
|
777
809
|
}
|