browserino 2.10.1.1 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/index.html ADDED
@@ -0,0 +1,719 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-us">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Browserino by SidOfc</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
8
+ <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
9
+ <link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
10
+ <link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
11
+ </head>
12
+ <body>
13
+ <section class="page-header">
14
+ <h1 class="project-name">Browserino</h1>
15
+ <h2 class="project-tagline">A ruby browser (dare I say) sniffer</h2>
16
+ <a href="https://github.com/SidOfc/browserino" class="btn">View on GitHub</a>
17
+ <a href="https://github.com/SidOfc/browserino/zipball/master" class="btn">Download .zip</a>
18
+ <a href="https://github.com/SidOfc/browserino/tarball/master" class="btn">Download .tar.gz</a>
19
+ </section>
20
+
21
+ <section class="main-content">
22
+ <h1>
23
+ <a id="browserino" class="anchor" href="#browserino" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Browserino</h1>
24
+
25
+ <p>A UserAgent sniffer with Rails &gt;= 3.2.0 integration.
26
+ The sniffer can currently identify 22 bots (of which 6 social media and 5 search engines), 14 browsers, 9 operating systems, 6 programming language UA's and 4 consoles.</p>
27
+
28
+ <h2>
29
+ <a id="status" class="anchor" href="#status" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Status</h2>
30
+
31
+ <p><a href="http://badge.fury.io/rb/browserino"><img src="https://badge.fury.io/rb/browserino.svg" alt="Gem Version"></a>
32
+ <a href="https://travis-ci.org/SidOfc/browserino"><img src="https://travis-ci.org/SidOfc/browserino.svg?branch=master" alt="Build Status"></a>
33
+ <a href="https://coveralls.io/github/SidOfc/browserino?branch=master"><img src="https://coveralls.io/repos/SidOfc/browserino/badge.svg?branch=master&amp;service=github" alt="Coverage Status"></a></p>
34
+
35
+ <hr>
36
+
37
+ <p>Useragent references:</p>
38
+
39
+ <ul>
40
+ <li><a href="http://useragentstring.com/">http://useragentstring.com/</a></li>
41
+ <li><a href="http://www.zytrax.com/tech/web/mobile_ids.html">http://www.zytrax.com/tech/web/mobile_ids.html</a></li>
42
+ <li><a href="http://www.user-agents.org/">http://www.user-agents.org/</a></li>
43
+ </ul>
44
+
45
+ <h2>
46
+ <a id="changelog" class="anchor" href="#changelog" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Changelog</h2>
47
+
48
+ <p><em>dates are in dd-mm-yyyy format</em><br>
49
+ <em>older changes can be found in the <a href="CHANGELOG.md">CHANGELOG.md</a></em></p>
50
+
51
+ <h4>
52
+ <a id="19-10-2016-version-21011" class="anchor" href="#19-10-2016-version-21011" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>19-10-2016 VERSION 2.10.1.1</h4>
53
+
54
+ <ul>
55
+ <li>Test on ruby 2.3.1</li>
56
+ <li>Fix missing questionmarks on method names in the README.</li>
57
+ <li>Change gem homepage to io domain</li>
58
+ </ul>
59
+
60
+ <h4>
61
+ <a id="25-08-2016-version-2101" class="anchor" href="#25-08-2016-version-2101" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>25-08-2016 VERSION 2.10.1</h4>
62
+
63
+ <ul>
64
+ <li>Replaced <code>require</code> with <code>require_relative</code> where possible</li>
65
+ <li>Fixed cli not loading due to failing <code>require</code>
66
+ </li>
67
+ </ul>
68
+
69
+ <h4>
70
+ <a id="24-07-2016-version-2100" class="anchor" href="#24-07-2016-version-2100" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>24-07-2016 VERSION 2.10.0</h4>
71
+
72
+ <ul>
73
+ <li>
74
+ <p>Added support for the servo browser:</p>
75
+
76
+ <ul>
77
+ <li>Added <code>servo?</code> method</li>
78
+ </ul>
79
+ </li>
80
+ <li>
81
+ <p>Added detection for various programming languages:</p>
82
+
83
+ <ul>
84
+ <li>Added <code>library?</code> method</li>
85
+ <li>Added <code>php?</code> method</li>
86
+ <li>Added <code>perl?</code> method</li>
87
+ <li>Added <code>python?</code> method</li>
88
+ <li>Added <code>java?</code> method</li>
89
+ <li>Added <code>curl?</code> method</li>
90
+ <li>Added <code>pycurl?</code> method</li>
91
+ </ul>
92
+ </li>
93
+ </ul>
94
+
95
+ <h2>
96
+ <a id="installation" class="anchor" href="#installation" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Installation</h2>
97
+
98
+ <p>Add the following to your applications Gemfile:</p>
99
+
100
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-k">gem</span> <span class="pl-s"><span class="pl-pds">'</span>browserino<span class="pl-pds">'</span></span></pre></div>
101
+
102
+ <p>And then execute:</p>
103
+
104
+ <pre><code>$ bundle
105
+ </code></pre>
106
+
107
+ <p>Or install it yourself with:</p>
108
+
109
+ <pre><code>$ gem install browserino
110
+ </code></pre>
111
+
112
+ <p>Browserino is tested with the following ruby versions</p>
113
+
114
+ <ul>
115
+ <li>1.9.3</li>
116
+ <li>2.0.0</li>
117
+ <li>2.1.0</li>
118
+ <li>2.2.1</li>
119
+ <li>2.3.0</li>
120
+ <li>2.3.1</li>
121
+ </ul>
122
+
123
+ <h2>
124
+ <a id="usage" class="anchor" href="#usage" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Usage</h2>
125
+
126
+ <p>After installing the gem globally or in your application you'll have to <code>require</code> the gem before being able to use it.</p>
127
+
128
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-k">require</span> <span class="pl-s"><span class="pl-pds">'</span>browserino<span class="pl-pds">'</span></span></pre></div>
129
+
130
+ <p>Afterwards, the gem is loaded and you can proceed by calling:</p>
131
+
132
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>&lt;user agent&gt;<span class="pl-pds">'</span></span></pre></div>
133
+
134
+ <p>Browserino is also usable in the command line</p>
135
+
136
+ <pre><code>~$ browserino parse &lt;ua&gt;
137
+ </code></pre>
138
+
139
+ <p>Output</p>
140
+
141
+ <pre><code>name: chrome, browser_version: 50.0.2661.102, engine_name: webkit, engine_version: 537.36, system_name: macintosh, system_architecture: nil
142
+ </code></pre>
143
+
144
+ <h3>
145
+ <a id="rails--320" class="anchor" href="#rails--320" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Rails (&gt;= 3.2.0)</h3>
146
+
147
+ <p>If you're using Rails (&gt;= 3.2.0) you'll have access to an <code>agent</code> object. Browserino will initialize itself using the <code>request.headers['User-Agent']</code></p>
148
+
149
+ <p>A quick example on how to get going:</p>
150
+
151
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-k">class</span> <span class="pl-en">ApplicationController<span class="pl-e"> &lt; ActionController::Base</span></span>
152
+ <span class="pl-k">def</span> <span class="pl-en">some_method</span>
153
+ render <span class="pl-c1">json:</span> agent
154
+ <span class="pl-k">end</span>
155
+ <span class="pl-k">end</span></pre></div>
156
+
157
+ <h3>
158
+ <a id="general" class="anchor" href="#general" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>General</h3>
159
+
160
+ <p>the <code>parse</code> method will <strong>always</strong> return a <code>Browserino::Agent</code> object.</p>
161
+
162
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>&lt;user agent&gt;<span class="pl-pds">'</span></span> <span class="pl-c"># =&gt; #&lt;Browserino::Agent:0x007f9b09b1fae8 ... &gt;</span></pre></div>
163
+
164
+ <h3>
165
+ <a id="default-return-values" class="anchor" href="#default-return-values" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Default return values</h3>
166
+
167
+ <p>If a property isn't available or not known to Browserino it's return value will always be <code>nil</code>, this can be tested by supplying an empty string (<code>''</code>) to <code>parse</code>:</p>
168
+
169
+ <div class="highlight highlight-source-ruby"><pre>agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>
170
+ agent.name
171
+ <span class="pl-c"># =&gt; nil</span></pre></div>
172
+
173
+ <p>If a value <em>is</em> found then you'll recieve a <em>lowercase string</em> containing the information:</p>
174
+
175
+ <div class="highlight highlight-source-ruby"><pre>agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) brave/0.7.7 Chrome/47.0.2526.73 Electron/0.36.2 Safari/537.36<span class="pl-pds">'</span></span>
176
+
177
+ agent.name
178
+ <span class="pl-c"># =&gt; 'brave'</span>
179
+
180
+ <span class="pl-c"># or using browser_name</span>
181
+
182
+ agent.browser_name
183
+ <span class="pl-c"># =&gt; 'brave'</span>
184
+
185
+ agent.browser_version
186
+ <span class="pl-c"># =&gt; '0.7.7'</span>
187
+
188
+ agent.engine_name
189
+ <span class="pl-c"># =&gt; 'webkit'</span></pre></div>
190
+
191
+ <p>Browserino also has some question methods, these will always return either <code>true</code> or <code>false</code>. The exceptions to this rule are methods that can take a name, for instance the <code>bot?</code> method:</p>
192
+
193
+ <div class="highlight highlight-source-ruby"><pre>agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>
194
+ agent.bot?
195
+ <span class="pl-c"># =&gt; true (empty UA's count as anonymous bots)</span>
196
+
197
+ agent.googlebot?
198
+ <span class="pl-c"># =&gt; false</span>
199
+
200
+ agent.non_supported_bot?
201
+ <span class="pl-c"># =&gt; NoMethodError</span>
202
+
203
+ agent.bot? <span class="pl-c1">:non_supported_bot</span>
204
+ <span class="pl-c"># =&gt; NoMethodError</span></pre></div>
205
+
206
+ <h3>
207
+ <a id="functions" class="anchor" href="#functions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Functions</h3>
208
+
209
+ <p>The samples below are all valid calls with their respective outputs, using the <code>agent</code> defined below.</p>
210
+
211
+ <div class="highlight highlight-source-ruby"><pre>agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko<span class="pl-pds">'</span></span></pre></div>
212
+
213
+ <h4>
214
+ <a id="note" class="anchor" href="#note" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Note</h4>
215
+
216
+ <p>The methods <code>social_media_name</code>, <code>search_engine_name</code>, <code>bot_name</code> and <code>browser_name</code>
217
+ are <em>all</em> aliasses of the general <code>name</code> method.</p>
218
+
219
+ <p>The exceptions to this rule are <code>system_name</code> and <code>console_name</code>. They each have their own method.</p>
220
+
221
+ <h5>
222
+ <a id="quick-usage" class="anchor" href="#quick-usage" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Quick usage</h5>
223
+
224
+ <div class="highlight highlight-source-ruby"><pre>agent.name
225
+ <span class="pl-c"># =&gt; 'ie'</span>
226
+
227
+ <span class="pl-c"># always returns real version, also when IE is in compat</span>
228
+ agent.browser_version
229
+ <span class="pl-c"># =&gt; '11.0'</span>
230
+
231
+ <span class="pl-c"># to get the compat version that IE is running in</span>
232
+ <span class="pl-c"># returns real version if not in compat mode</span>
233
+ agent.browser_version <span class="pl-c1">compat:</span> <span class="pl-c1">true</span>
234
+ <span class="pl-c"># =&gt; '11.0'</span>
235
+
236
+ agent.library_name
237
+ <span class="pl-c"># =&gt; nil</span>
238
+
239
+ agent.library_version
240
+ <span class="pl-c"># =&gt; nil</span>
241
+
242
+ agent.engine_name
243
+ <span class="pl-c"># =&gt; 'trident'</span>
244
+
245
+ agent.engine_version
246
+ <span class="pl-c"># =&gt; '7.0'</span>
247
+
248
+ agent.system_name
249
+ <span class="pl-c"># =&gt; 'windows'</span>
250
+
251
+ <span class="pl-c"># system_name attempts to find the operating systems version name</span>
252
+ <span class="pl-c"># when full: true is used</span>
253
+ <span class="pl-c"># returning an array with either the version name or nil if not found</span>
254
+ agent.system_name <span class="pl-c1">full:</span> <span class="pl-c1">true</span>
255
+ <span class="pl-c"># =&gt; ['windows', '7']</span>
256
+
257
+ agent.system_version
258
+ <span class="pl-c"># =&gt; '6.1'</span>
259
+
260
+ agent.system_architecture
261
+ <span class="pl-c"># =&gt; 'x64'</span>
262
+
263
+ agent.console_name
264
+ <span class="pl-c"># =&gt; nil</span>
265
+
266
+ <span class="pl-c"># two formats possible: 'aa' or `aa-bb`</span>
267
+ agent.locale
268
+ <span class="pl-c"># =&gt; 'as'</span></pre></div>
269
+
270
+ <h5>
271
+ <a id="question-methods" class="anchor" href="#question-methods" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Question methods</h5>
272
+
273
+ <p>Browserino also provides some question methods.</p>
274
+
275
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-c"># only for Internet Explorer</span>
276
+ agent.compat?
277
+ <span class="pl-c"># =&gt; false</span>
278
+
279
+ <span class="pl-c"># returns true if name is present</span>
280
+ agent.known?
281
+ <span class="pl-c"># =&gt; true</span>
282
+
283
+ <span class="pl-c"># returns true if browser is known</span>
284
+ agent.browser?
285
+ <span class="pl-c"># =&gt; true</span>
286
+
287
+ <span class="pl-c"># returns true if specific browser</span>
288
+ agent.browser? <span class="pl-c1">:ie</span>
289
+ <span class="pl-c"># =&gt; true</span>
290
+
291
+ <span class="pl-c"># returns true if specific browser and version</span>
292
+ agent.browser? <span class="pl-c1">:ie</span>, <span class="pl-c1">version:</span> <span class="pl-s"><span class="pl-pds">'</span>11.0<span class="pl-pds">'</span></span>
293
+
294
+ <span class="pl-c"># returns true if library is known</span>
295
+ agent.library?
296
+
297
+ <span class="pl-c"># returns true if specific library</span>
298
+ agent.library? <span class="pl-c1">:php</span>
299
+
300
+ <span class="pl-c"># returns true if specific library and version</span>
301
+ agent.library? <span class="pl-c1">:php</span>, <span class="pl-c1">version:</span> <span class="pl-s"><span class="pl-pds">'</span>5.9.0<span class="pl-pds">'</span></span>
302
+
303
+ <span class="pl-c"># returns true if there is a social media bot on your website</span>
304
+ agent.social_media?
305
+ <span class="pl-c"># =&gt; false</span>
306
+
307
+ <span class="pl-c"># returns true if platform is known</span>
308
+ agent.platform?
309
+ <span class="pl-c"># =&gt; true</span>
310
+
311
+ <span class="pl-c"># returns true if specific platform</span>
312
+ agent.platform? <span class="pl-c1">:windows</span>
313
+ <span class="pl-c"># =&gt; true</span>
314
+
315
+ <span class="pl-c"># returns true if specific platform and version</span>
316
+ agent.platform? <span class="pl-c1">:windows</span>, <span class="pl-c1">version:</span> <span class="pl-s"><span class="pl-pds">'</span>7<span class="pl-pds">'</span></span>
317
+ <span class="pl-c"># =&gt; true</span>
318
+
319
+ <span class="pl-c"># returns true if console is known</span>
320
+ agent.console?
321
+ <span class="pl-c"># =&gt; false</span>
322
+
323
+ <span class="pl-c"># returns true if specific console</span>
324
+ agent.console? <span class="pl-c1">:xbox</span>
325
+ <span class="pl-c"># =&gt; false</span>
326
+
327
+ <span class="pl-c"># returns true if user agent is empty or a bot is recognized</span>
328
+ agent.bot?
329
+ <span class="pl-c"># =&gt; false</span>
330
+
331
+ agent.x64?
332
+ <span class="pl-c"># =&gt; true</span>
333
+
334
+ agent.x32?
335
+ <span class="pl-c"># =&gt; false</span>
336
+
337
+ agent.mobile?
338
+ <span class="pl-c"># =&gt; false</span></pre></div>
339
+
340
+ <p>The above methods are the base questions you can ask but there are a lot more methods you can call on the <code>agent</code>. Every supported browser, operating system or bot is basically a question method so you could do this:</p>
341
+
342
+ <div class="highlight highlight-source-ruby"><pre>agent.windows?
343
+ <span class="pl-c"># =&gt; true</span>
344
+
345
+ <span class="pl-c"># based on full name</span>
346
+ agent.windows? <span class="pl-s"><span class="pl-pds">'</span>7<span class="pl-pds">'</span></span>
347
+ <span class="pl-c"># =&gt; true</span>
348
+
349
+ <span class="pl-c"># NT versions also work</span>
350
+ agent.windows? <span class="pl-c1">6.1</span>
351
+ <span class="pl-c"># =&gt; true</span></pre></div>
352
+
353
+ <h5>
354
+ <a id="transformation" class="anchor" href="#transformation" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Transformation</h5>
355
+
356
+ <p>Browserino implements <code>to_a</code>, <code>to_h</code> and <code>to_s</code> to allow for collected data to be moved around without attaching the entire object with methods.</p>
357
+
358
+ <p><strong>to_s</strong></p>
359
+
360
+ <p>Returns a compiled string of properties based on available information.</p>
361
+
362
+ <div class="highlight highlight-source-ruby"><pre>agent.to_s
363
+ <span class="pl-c"># =&gt; 'ie ie11 trident trident7 windows x64'</span>
364
+
365
+ <span class="pl-c"># a seperator can be passed to format the name + version combo's</span>
366
+ agent.to_s <span class="pl-s"><span class="pl-pds">'</span>-<span class="pl-pds">'</span></span>
367
+ <span class="pl-c"># =&gt; 'ie ie-11 trident trident-7 windows x64'</span></pre></div>
368
+
369
+ <p>If the agent object can't find a property in the user agent, that property will be excluded from the string.
370
+ For instance, if the <code>browser_version</code> and <code>engine_version</code> of the <code>agent</code> object are <code>nil</code> then the following will be returned:</p>
371
+
372
+ <div class="highlight highlight-source-ruby"><pre>agent.to_s
373
+ <span class="pl-c"># =&gt; ie trident windows x64</span></pre></div>
374
+
375
+ <p><strong>to_a</strong></p>
376
+
377
+ <p>Returns an array with key =&gt; value pairs.</p>
378
+
379
+ <div class="highlight highlight-source-ruby"><pre>agent.to_a
380
+ <span class="pl-c"># =&gt; [[:name, "ie"],</span>
381
+ <span class="pl-c"># [:browser_version, "11.0"],</span>
382
+ <span class="pl-c"># [:engine_name, "trident"],</span>
383
+ <span class="pl-c"># [:engine_version, "7.0"],</span>
384
+ <span class="pl-c"># [:system_name, "windows"],</span>
385
+ <span class="pl-c"># [:system_version, "6.1"],</span>
386
+ <span class="pl-c"># [:system_architecture, "x64"],</span>
387
+ <span class="pl-c"># [:console_name, nil],</span>
388
+ <span class="pl-c"># [:locale, "as"]]</span></pre></div>
389
+
390
+ <p><strong>to_h</strong></p>
391
+
392
+ <p>Returns a hash with key =&gt; value pairs.</p>
393
+
394
+ <div class="highlight highlight-source-ruby"><pre>agent.to_h
395
+ <span class="pl-c"># =&gt; {:name=&gt;"ie",</span>
396
+ <span class="pl-c"># :browser_version=&gt;"11.0",</span>
397
+ <span class="pl-c"># :engine_name=&gt;"trident",</span>
398
+ <span class="pl-c"># :engine_version=&gt;"7.0",</span>
399
+ <span class="pl-c"># :system_name=&gt;"windows",</span>
400
+ <span class="pl-c"># :system_version=&gt;"6.1",</span>
401
+ <span class="pl-c"># :system_architecture=&gt;"x64",</span>
402
+ <span class="pl-c"># :console_name =&gt; nil,</span>
403
+ <span class="pl-c"># :locale=&gt;"as"}</span></pre></div>
404
+
405
+ <h5>
406
+ <a id="supplying-versions" class="anchor" href="#supplying-versions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Supplying versions</h5>
407
+
408
+ <p>Consider this parsed string:</p>
409
+
410
+ <div class="highlight highlight-source-ruby"><pre>agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>Mozilla/5.0 (Linux; U; Android 4.1.2; en-us; SM-T210R Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 UCBrowser/2.3.2.300<span class="pl-pds">'</span></span>
411
+
412
+ <span class="pl-c"># output for system_name</span>
413
+ agent.system_name
414
+ <span class="pl-c"># =&gt; 'android'</span>
415
+
416
+ <span class="pl-c"># output for system_name full: true</span>
417
+ agent.system_name <span class="pl-c1">full:</span> <span class="pl-c1">true</span>
418
+ <span class="pl-c"># =&gt; ['android', 'Jelly Bean 16']</span></pre></div>
419
+
420
+ <p>When supplying a version to a method that supports it, you have multiple options for the format of that version.</p>
421
+
422
+ <ul>
423
+ <li>Using a symbol or string without version: <code>:jelly_bean</code> or <code>'jelly_bean'</code>
424
+ </li>
425
+ <li>Using a symbol or string with version: <code>:jelly_bean_16</code> or <code>'jelly_bean_16'</code>
426
+ </li>
427
+ <li>Using a string: <code>'4.1.2'</code><br>
428
+ </li>
429
+ <li>Using a float: <code>4.1</code>
430
+ </li>
431
+ <li>Using an int: <code>4</code>
432
+ </li>
433
+ </ul>
434
+
435
+ <p>When calling the <code>platform?</code> or <code>android?</code> functions with the above examples, they would all match since the method that compares versions also checks how specific the version is that you want to compare against.</p>
436
+
437
+ <p>If you pass in <code>4.1</code> as a version the matcher will look for <code>x.x</code> in the extracted version and discard the unspecified value, this allows for you to be explicitly less specific to allow for a greater range of systems to be matched.</p>
438
+
439
+ <ul>
440
+ <li>
441
+ <code>4.1.2</code> will match <code>4.1.2</code>
442
+ </li>
443
+ <li>
444
+ <code>4.1</code> will match <code>4.1.x</code>
445
+ </li>
446
+ <li>
447
+ <code>4</code> will match <code>4.x.x</code>
448
+ </li>
449
+ </ul>
450
+
451
+ <p><strong>Examples using <code>platform?</code></strong></p>
452
+
453
+ <div class="highlight highlight-source-ruby"><pre>agent.platform? <span class="pl-c1">:android</span>, <span class="pl-c1">version:</span> <span class="pl-s"><span class="pl-pds">'</span>4.1.2<span class="pl-pds">'</span></span>
454
+ <span class="pl-c"># =&gt; true</span>
455
+
456
+ agent.platform? <span class="pl-c1">:android</span>, <span class="pl-c1">version:</span> <span class="pl-c1">4.1</span>
457
+ <span class="pl-c"># =&gt; true</span>
458
+
459
+ agent.platform? <span class="pl-c1">:android</span>, <span class="pl-c1">version:</span> <span class="pl-c1">4</span>
460
+ <span class="pl-c"># =&gt; true</span>
461
+
462
+ agent.platform? <span class="pl-c1">:android</span>, <span class="pl-c1">version:</span> <span class="pl-c1">:jelly_bean</span>
463
+ <span class="pl-c"># =&gt; true</span>
464
+
465
+ agent.platform? <span class="pl-c1">:android</span>, <span class="pl-c1">version:</span> <span class="pl-c1">:jelly_bean_16</span>
466
+ <span class="pl-c"># =&gt; true</span></pre></div>
467
+
468
+ <h5>
469
+ <a id="platform-browser-bot-console-search_engine-library-and-social_media-methods" class="anchor" href="#platform-browser-bot-console-search_engine-library-and-social_media-methods" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><code>platform?</code>, <code>browser?</code>, <code>bot?</code>, <code>console?</code>, <code>search_engine?</code>, <code>library</code> and <code>social_media?</code> methods</h5>
470
+
471
+ <p>As you've seen above, the <code>platform?</code> function can take two arguments, a symbol with the system name and optionally a hash with a <code>:version</code> key to supply a version, the <code>browser?</code> and <code>library?</code> method works in exactly the same way.</p>
472
+
473
+ <p>The <code>bot?</code> and <code>social_media?</code> methods however aren't that complex since you don't need to know a bot / social media version or anything other than it's name so inside these methods, only a name can be passed:</p>
474
+
475
+ <p><em>Every social media match is automatically a bot, but a bot isn't automatically social media, <strong>This is also true for the <code>search_engine?</code> method</strong></em></p>
476
+
477
+ <div class="highlight highlight-source-ruby"><pre><span class="pl-c"># when a bot UA gets parsed</span>
478
+ agent <span class="pl-k">=</span> <span class="pl-c1">Browserino</span>.parse <span class="pl-s"><span class="pl-pds">'</span>facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)<span class="pl-pds">'</span></span>
479
+
480
+ agent.bot?
481
+ <span class="pl-c"># =&gt; true</span>
482
+
483
+ agent.social_media?
484
+ <span class="pl-c"># =&gt; true</span>
485
+
486
+ agent.bot? <span class="pl-c1">:facebook</span>
487
+ <span class="pl-c"># =&gt; true</span>
488
+
489
+ agent.social_media? <span class="pl-c1">:facebook</span>
490
+ <span class="pl-c"># =&gt; true</span>
491
+
492
+ agent.bot? <span class="pl-c1">:facebook</span>, <span class="pl-c1">version:</span> <span class="pl-c1">1.1</span>
493
+ <span class="pl-c"># =&gt; ArgumentError</span></pre></div>
494
+
495
+ <h5>
496
+ <a id="checking-a-specific-browser-system-bot-library-or-social-media" class="anchor" href="#checking-a-specific-browser-system-bot-library-or-social-media" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Checking a specific browser, system, bot, library or social media</h5>
497
+
498
+ <p>Every name you see in the below lists can be passed as symbol or string to their respective method</p>
499
+
500
+ <p><strong>search engine</strong></p>
501
+
502
+ <ul>
503
+ <li><code>google</code></li>
504
+ <li><code>bing</code></li>
505
+ <li><code>yahoo_slurp</code></li>
506
+ <li><code>baiduspider</code></li>
507
+ <li>
508
+ <code>duckduckgo</code> or <code>ddg</code>
509
+ </li>
510
+ </ul>
511
+
512
+ <p>Examples:</p>
513
+
514
+ <div class="highlight highlight-source-ruby"><pre>agent.google?
515
+ agent.baiduspider?
516
+
517
+ <span class="pl-c"># using the search_engine? method</span>
518
+ agent.search_engine? <span class="pl-c1">:google</span>
519
+
520
+ <span class="pl-c"># using shorthand</span>
521
+ agent.search_engine? <span class="pl-c1">:ddg</span></pre></div>
522
+
523
+ <p><strong>consoles</strong></p>
524
+
525
+ <ul>
526
+ <li><code>xbox</code></li>
527
+ <li><code>nintendo_ds</code></li>
528
+ <li><code>wii</code></li>
529
+ <li><code>playstation</code></li>
530
+ </ul>
531
+
532
+ <p>Examples:</p>
533
+
534
+ <div class="highlight highlight-source-ruby"><pre>agent.playstation?
535
+ agent.wii?
536
+
537
+ agent.console?
538
+
539
+ agent.console? <span class="pl-c1">:facebook</span></pre></div>
540
+
541
+ <p><strong>social media</strong></p>
542
+
543
+ <ul>
544
+ <li>
545
+ <code>facebook</code> or <code>fb</code>
546
+ </li>
547
+ <li><code>twitter</code></li>
548
+ <li><code>linkedin</code></li>
549
+ <li><code>instagram</code></li>
550
+ <li><code>pinterest</code></li>
551
+ <li><code>tumblr</code></li>
552
+ </ul>
553
+
554
+ <p>Examples:</p>
555
+
556
+ <div class="highlight highlight-source-ruby"><pre>agent.facebook?
557
+ agent.tumblr?
558
+
559
+ <span class="pl-c"># using the social_media? method</span>
560
+ agent.social_media? <span class="pl-c1">:facebook</span>
561
+
562
+ <span class="pl-c"># using shorthand</span>
563
+ agent.social_media? <span class="pl-c1">:fb</span>
564
+
565
+ agent.social_media? <span class="pl-c1">:tumblr</span></pre></div>
566
+
567
+ <p><strong>bot</strong></p>
568
+
569
+ <ul>
570
+ <li><code>google</code></li>
571
+ <li><code>msn</code></li>
572
+ <li><code>bing</code></li>
573
+ <li><code>yahoo_slurp</code></li>
574
+ <li><code>baiduspider</code></li>
575
+ <li><code>yandex</code></li>
576
+ <li><code>sosospider</code></li>
577
+ <li><code>exa</code></li>
578
+ <li><code>sogou_spider</code></li>
579
+ </ul>
580
+
581
+ <p>Examples:</p>
582
+
583
+ <div class="highlight highlight-source-ruby"><pre>agent.google?
584
+ agent.exa?
585
+
586
+ <span class="pl-c"># using the bot? method</span>
587
+ agent.bot? <span class="pl-c1">:google</span>
588
+ agent.bot? <span class="pl-c1">:exa</span></pre></div>
589
+
590
+ <p><strong>library</strong></p>
591
+
592
+ <ul>
593
+ <li><code>php</code></li>
594
+ <li><code>perl</code></li>
595
+ <li><code>curl</code></li>
596
+ <li><code>python</code></li>
597
+ <li><code>java</code></li>
598
+ <li><code>pycurl</code></li>
599
+ </ul>
600
+
601
+ <p>Examples:</p>
602
+
603
+ <div class="highlight highlight-source-ruby"><pre>agent.php?
604
+ agent.pycurl?
605
+
606
+ agent.library?
607
+
608
+ agent.library? <span class="pl-c1">:curl</span>
609
+
610
+ agent.library? <span class="pl-c1">:curl</span>, <span class="pl-c1">version:</span> <span class="pl-c1">7.21</span></pre></div>
611
+
612
+ <p><strong>browser</strong></p>
613
+
614
+ <ul>
615
+ <li><code>chrome</code></li>
616
+ <li>
617
+ <code>firefox</code> or <code>ff</code>
618
+ </li>
619
+ <li><code>servo</code></li>
620
+ <li><code>seamonkey</code></li>
621
+ <li><code>opera</code></li>
622
+ <li><code>opera_mini</code></li>
623
+ <li><code>vivaldi</code></li>
624
+ <li><code>ucbrowser</code></li>
625
+ <li><code>maxthon</code></li>
626
+ <li><code>bolt</code></li>
627
+ <li><code>brave</code></li>
628
+ <li><code>safari</code></li>
629
+ <li><code>ie</code></li>
630
+ <li><code>edge</code></li>
631
+ </ul>
632
+
633
+ <p>Examples:</p>
634
+
635
+ <div class="highlight highlight-source-ruby"><pre>agent.firefox?
636
+ agent.chrome? <span class="pl-c1">42</span>
637
+
638
+ <span class="pl-c"># using the browser? method</span>
639
+ agent.browser? <span class="pl-c1">:firefox</span>
640
+
641
+ <span class="pl-c"># using shorthand</span>
642
+ agent.browser? <span class="pl-c1">:ff</span>
643
+
644
+ agent.browser? <span class="pl-c1">:chrome</span>, <span class="pl-c1">version:</span> <span class="pl-c1">42</span></pre></div>
645
+
646
+ <p><strong>operating system</strong></p>
647
+
648
+ <ul>
649
+ <li>
650
+ <code>windows</code> or <code>win</code>
651
+ </li>
652
+ <li>
653
+ <code>macintosh</code> or <code>osx</code>
654
+ </li>
655
+ <li><code>linux</code></li>
656
+ <li><code>bsd</code></li>
657
+ <li><code>solaris</code></li>
658
+ <li><code>android</code></li>
659
+ <li><code>ios</code></li>
660
+ <li>
661
+ <code>blackberry</code> or <code>bb</code>
662
+ </li>
663
+ <li><code>windows_phone</code></li>
664
+ </ul>
665
+
666
+ <p>Examples:</p>
667
+
668
+ <div class="highlight highlight-source-ruby"><pre>agent.macintosh?
669
+ agent.windows_phone? <span class="pl-c1">7</span>
670
+
671
+ <span class="pl-c"># to check for windows vista one could do</span>
672
+ agent.windows? <span class="pl-c1">6</span>
673
+
674
+ <span class="pl-c"># a more readable equivelant</span>
675
+ agent.windows? <span class="pl-c1">:vista</span>
676
+
677
+ <span class="pl-c"># using the platform? method</span>
678
+ agent.platform? <span class="pl-c1">:macintosh</span>
679
+
680
+ <span class="pl-c"># using shorthand</span>
681
+ agent.platform? <span class="pl-c1">:osx</span>
682
+
683
+ agent.platform? <span class="pl-c1">:windows_phone</span>, <span class="pl-c1">version:</span> <span class="pl-c1">7</span></pre></div>
684
+
685
+ <p>Notes:</p>
686
+
687
+ <ul>
688
+ <li>
689
+ <code>linux?</code> doesn't support any versions</li>
690
+ <li>
691
+ <code>bsd?</code> doesn't support any versions</li>
692
+ <li>
693
+ <code>solaris?</code> only supports numeric versions</li>
694
+ <li>
695
+ <em>named versions</em> are only supported if they are present in a <a href="https://github.com/SidOfc/browserino/tree/master/lib/browserino/maps">map</a>
696
+ </li>
697
+ </ul>
698
+
699
+ <h2>
700
+ <a id="contributing" class="anchor" href="#contributing" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Contributing</h2>
701
+
702
+ <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/SidOfc/browserino">https://github.com/SidOfc/browserino</a>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="contributor-covenant.org">Contributor Covenant</a> code of conduct.</p>
703
+
704
+ <h2>
705
+ <a id="license" class="anchor" href="#license" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>License</h2>
706
+
707
+ <p>The gem is available as open source under the terms of the <a href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
708
+
709
+ <footer class="site-footer">
710
+ <span class="site-footer-owner"><a href="https://github.com/SidOfc/browserino">Browserino</a> is maintained by <a href="https://github.com/SidOfc">SidOfc</a>.</span>
711
+
712
+ <span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
713
+ </footer>
714
+
715
+ </section>
716
+
717
+
718
+ </body>
719
+ </html>