docs/Brauser/Browser.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: Brauser::Browser
— Documentation by YARD 0.8.7.6
</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '../';
framesUrl = "../frames.html#!Brauser/Browser.html";
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="../_index.html">Index (B)</a> »
<span class='title'><span class='object_link'><a href="../Brauser.html" title="Brauser (module)">Brauser</a></span></span>
»
<span class="title">Browser</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="../method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="../file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: Brauser::Browser
</h1>
<dl class="box">
<dt class="r1">Inherits:</dt>
<dd class="r1">
<span class="inheritName">Object</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Brauser::Browser</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">lib/brauser/browser.rb</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>This class represents a detection of the current user browser.</p>
</div>
</div>
<div class="tags">
</div>
<h2>Constant Summary</h2>
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#accept_language-instance_method" title="#accept_language (instance method)">- (String) <strong>accept_language</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>The raw Accept-Language HTTP header.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#agent-instance_method" title="#agent (instance method)">- (String) <strong>agent</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>The raw User-Agent HTTP header.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#human_languages-instance_method" title="#human_languages (instance method)">- (Hash) <strong>human_languages</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The human-readable list of accepted languages.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#human_name-instance_method" title="#human_name (instance method)">- (String) <strong>human_name</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The human-readable current browser name.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#human_platform-instance_method" title="#human_platform (instance method)">- (String) <strong>human_platform</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The human-readable current browser platform.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#languages-instance_method" title="#languages (instance method)">- (Hash) <strong>languages</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The accepted languages.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#name-instance_method" title="#name (instance method)">- (Symbol) <strong>name</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The current browser name.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#platform-instance_method" title="#platform (instance method)">- (Symbol) <strong>platform</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The current browser platform.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#version-instance_method" title="#version (instance method)">- (Versionomy::Value) <strong>version</strong> </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The current browser version.</p>
</div></span>
</li>
</ul>
<h2>
Instance Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#accepts%3F-instance_method" title="#accepts? (instance method)">- (Boolean) <strong>accepts?</strong>(*languages) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Checks if the browser accepts a specific language or languages.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#classes-instance_method" title="#classes (instance method)">- (String|Array) <strong>classes</strong>(join = " ", name: true, version: true, platform: true) </a>
(also: #meta, #to_s)
</span>
<span class="summary_desc"><div class='inline'><p>Returns an array of information about the browser.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Browser) <strong>initialize</strong>(agent = "", accept_language = "") </a>
</span>
<span class="note title constructor">constructor</span>
<span class="summary_desc"><div class='inline'><p>Creates a new browser.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#is%3F-instance_method" title="#is? (instance method)">- (Boolean) <strong>is?</strong>(name: nil, engine: nil, version: nil, platform: nil, languages: nil) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Checks if the browser matches a specific query.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#method_missing-instance_method" title="#method_missing (instance method)">- (Boolean) <strong>method_missing</strong>(method, *args, &block) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Check if the browser is a specific one.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#supported%3F-instance_method" title="#supported? (instance method)">- (Boolean) <strong>supported?</strong>(browsers = {}) </a>
</span>
<span class="summary_desc"><div class='inline'><p>Check if the browser is supported.</p>
</div></span>
</li>
</ul>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
- (<tt><span class='object_link'><a href="" title="Brauser::Browser (class)">Browser</a></span></tt>) <strong>initialize</strong>(agent = "", accept_language = "")
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new browser.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>agent</span>
<span class='type'>(<tt>String</tt>)</span>
<em class="default">(defaults to: <tt>""</tt>)</em>
—
<div class='inline'><p>The User-Agent HTTP header.</p>
</div>
</li>
<li>
<span class='name'>accept_language</span>
<span class='type'>(<tt>String</tt>)</span>
<em class="default">(defaults to: <tt>""</tt>)</em>
—
<div class='inline'><p>The Accept-Language HTTP header.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
37
38
39
40
41</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 37</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="method_missing_details" class="method_details_list">
<h2>Dynamic Method Handling</h2>
<p class="notice this">
This class handles dynamic methods through the <tt>method_missing</tt> method
</p>
<div class="method_details first">
<h3 class="signature first" id="method_missing-instance_method">
- (<tt>Boolean</tt>) <strong>method_missing</strong>(method, *args, &block)
</h3><div class="docstring">
<div class="discussion">
<p>Check if the browser is a specific one</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>method</span>
<span class='type'></span>
—
<div class='inline'><p>The browser engine to check.</p>
</div>
</li>
<li>
<span class='name'>args</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p><strong>unused.</strong></p>
</div>
</li>
<li>
<span class='name'>block</span>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p><strong>unused.</strong></p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p><code>true</code> if browser match the engine, <code>false</code> otherwise.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
109
110
111</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 109</span>
<span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_attr_details" class="attr_details">
<h2>Instance Attribute Details</h2>
<span id="accept_language=-instance_method"></span>
<div class="method_details first">
<h3 class="signature first" id="accept_language-instance_method">
- (<tt>String</tt>) <strong>accept_language</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The raw Accept-Language HTTP header.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The raw Accept-Language HTTP header.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id="agent=-instance_method"></span>
<div class="method_details ">
<h3 class="signature " id="agent-instance_method">
- (<tt>String</tt>) <strong>agent</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The raw User-Agent HTTP header.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The raw User-Agent HTTP header.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="human_languages-instance_method">
- (<tt>Hash</tt>) <strong>human_languages</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The human-readable list of accepted languages.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Hash</tt>)</span>
—
<div class='inline'><p>The human-readable list of accepted languages.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="human_name-instance_method">
- (<tt>String</tt>) <strong>human_name</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The human-readable current browser name.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The human-readable current browser name.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="human_platform-instance_method">
- (<tt>String</tt>) <strong>human_platform</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The human-readable current browser platform.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The human-readable current browser platform.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="languages-instance_method">
- (<tt>Hash</tt>) <strong>languages</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The accepted languages.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Hash</tt>)</span>
—
<div class='inline'><p>The accepted languages.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="name-instance_method">
- (<tt>Symbol</tt>) <strong>name</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The current browser name.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Symbol</tt>)</span>
—
<div class='inline'><p>The current browser name.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="platform-instance_method">
- (<tt>Symbol</tt>) <strong>platform</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The current browser platform.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Symbol</tt>)</span>
—
<div class='inline'><p>The current browser platform.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<span id=""></span>
<div class="method_details ">
<h3 class="signature " id="version-instance_method">
- (<tt>Versionomy::Value</tt>) <strong>version</strong> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The current browser version.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Versionomy::Value</tt>)</span>
—
<div class='inline'><p>The current browser version.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 28</span>
<span class='kw'>class</span> <span class='const'>Browser</span>
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:agent</span><span class='comma'>,</span> <span class='symbol'>:accept_language</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:human_name</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:platform</span><span class='comma'>,</span> <span class='symbol'>:human_platform</span><span class='comma'>,</span> <span class='symbol'>:languages</span><span class='comma'>,</span> <span class='symbol'>:human_languages</span>
<span class='id identifier rubyid_alias_attribute'>alias_attribute</span> <span class='symbol'>:ua</span><span class='comma'>,</span> <span class='symbol'>:agent</span>
<span class='comment'># Creates a new browser.
</span> <span class='comment'>#
</span> <span class='comment'># @param agent [String] The User-Agent HTTP header.
</span> <span class='comment'># @param accept_language [String] The Accept-Language HTTP header.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_accept_language'>accept_language</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@agent</span> <span class='op'>=</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@accept_language</span> <span class='op'>=</span> <span class='id identifier rubyid_accept_language'>accept_language</span>
<span class='id identifier rubyid_parse'>parse</span>
<span class='kw'>end</span>
<span class='comment'># Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.
</span> <span class='comment'>#
</span> <span class='comment'># For version, it will be included a class for every token of the version. For example, version `7.0.1.2` will return this:
</span> <span class='comment'>#
</span> <span class='comment'># ```ruby
</span> <span class='comment'># ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</span> <span class='comment'># ```
</span> <span class='comment'>#
</span> <span class='comment'># If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.
</span> <span class='comment'>#
</span> <span class='comment'># @param join [String|NilClass] If non falsy, the separator to use to join information. If falsy, informations will be returned as array.
</span> <span class='comment'># @param name [Boolean] If non falsy, the string to prepend to the name. If falsy, the name information will not be included.
</span> <span class='comment'># @param version [String|NilClass] If non falsy, the string to prepend to the version. If falsy, the version information will not be included.
</span> <span class='comment'># @param platform [String|NilClass] If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.
</span> <span class='comment'># @return [String|Array] CSS ready information of the current browser.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:meta</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:to_s</span><span class='comma'>,</span> <span class='symbol'>:classes</span>
<span class='comment'># Checks if the browser accepts a specific language or languages.
</span> <span class='comment'>#
</span> <span class='comment'># @param languages [Array] The list of languages.
</span> <span class='comment'># @return [Boolean] `true` if at least one of requested languages is accepted, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span>
<span class='comment'># Checks if the browser matches a specific query.
</span> <span class='comment'>#
</span> <span class='comment'># @param name [Symbol|Array|NilClass] The list of names to check. Also, this meta-name is supported: `:tablet`.
</span> <span class='comment'># @param engine [Symbol|Array|NilClass] Alias for `name`, **which has precedence over this.**
</span> <span class='comment'># @param version [String|NilClass] The query to match the version.
</span> <span class='comment'># It must be a query in the form is `OPERATOR VALUE && ..`, where `OPERATOR` is one of `["<", "<=", "=", "==", ">=", ">"]`.
</span> <span class='comment'># You can also pass the value "capable", which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.
</span> <span class='comment'># @param platform [Symbol|Array|NilClass] The list of platforms to check.
</span> <span class='comment'># @param languages [Symbol|Array|NilClass] The list of languages to check.
</span> <span class='comment'># @return [Boolean] `true` if browser match the query, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is supported.
</span> <span class='comment'>#
</span> <span class='comment'># @param browsers [Hash|String] A map of name and minimum supported major version, or a path to YAML file containing the map.
</span> <span class='comment'># @return [Boolean] `true` if current browser is supported, `false` otherwise. If the name is not found in the map, `false` is returned.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span>
<span class='comment'># Check if the browser is a specific one
</span> <span class='comment'>#
</span> <span class='comment'># @param method The browser engine to check.
</span> <span class='comment'># @param args [Array] **unused.**
</span> <span class='comment'># @param block [Proc] **unused.**
</span> <span class='comment'># @return [Boolean] `true` if browser match the engine, `false` otherwise.
</span> <span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_method'>method</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(.+)\?$</span><span class='regexp_end'>/</span></span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_last_match'>last_match</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_private'>private</span>
<span class='comment'># :nodoc:
</span> <span class='const'>VERSION_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<operator>>=|<=|<|>|!=|(={1,2}))\s*(?<version>.+)</span><span class='regexp_end'>/</span></span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_agent'>agent</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_agent'>parse_agent</span><span class='lparen'>(</span><span class='ivar'>@agent</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@name</span><span class='comma'>,</span> <span class='ivar'>@version</span><span class='comma'>,</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='op'>*</span><span class='id identifier rubyid_agent'>agent</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_browsers'>browsers</span><span class='lbracket'>[</span><span class='ivar'>@name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Browser</span><span class='tstring_end'>"</span></span>
<span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_platforms'>platforms</span><span class='lbracket'>[</span><span class='ivar'>@platform</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_try'>try</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown Platform</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_sanitize_agent'>sanitize_agent</span>
<span class='ivar'>@name</span> <span class='op'>=</span> <span class='ivar'>@platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:unknown</span><span class='rparen'>)</span>
<span class='ivar'>@human_name</span> <span class='op'>=</span> <span class='ivar'>@human_platform</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unknown</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_languages'>parse_languages</span><span class='lparen'>(</span><span class='id identifier rubyid_parser'>parser</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_parse_accept_language'>parse_accept_language</span><span class='lparen'>(</span><span class='ivar'>@accept_language</span><span class='rparen'>)</span>
<span class='ivar'>@languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='ivar'>@human_languages</span> <span class='op'>=</span> <span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_priority'>priority</span><span class='rparen'>)</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span><span class='lbracket'>[</span><span class='const'>Brauser</span><span class='op'>::</span><span class='const'>Definitions</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_priority'>priority</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='ivar'>@name</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:msie_compatibility</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>==</span> <span class='symbol'>:msie_compatibility</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version_str'>version_str</span> <span class='op'>=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_values_array'>values_array</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='op'>|</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='comma'>,</span> <span class='id identifier rubyid_current'>current</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_version_str'>version_str</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_version'>version</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>platform-</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>TrueClass</span><span class='rparen'>)</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sanitizer'>sanitizer</span> <span class='op'>=</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_arguments'>arguments</span> <span class='op'>?</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_ensure_array'>ensure_array</span><span class='lparen'>(</span><span class='label'>no_duplicates:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>compact:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>flatten:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_sanitizer'>sanitizer</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:msie</span><span class='comma'>,</span> <span class='symbol'>:msie_compatibility</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_names'>names</span> <span class='op'>&</span> <span class='lbracket'>[</span><span class='symbol'>:ie</span><span class='comma'>,</span> <span class='symbol'>:msie</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:chromium</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:chrome</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='symbol'>:ipad</span><span class='comma'>,</span> <span class='symbol'>:android</span><span class='comma'>,</span> <span class='symbol'>:kindle</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:tablet</span><span class='rparen'>)</span>
<span class='id identifier rubyid_names'>names</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span> <span class='op'>==</span> <span class='symbol'>:capable</span> <span class='op'>?</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span> <span class='op'>:</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_version'>check_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span> <span class='op'>=</span> <span class='const'>StringScanner</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>true</span>
<span class='kw'>until</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_eos?'>eos?</span>
<span class='id identifier rubyid_token'>token</span> <span class='op'>=</span> <span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_scan_until'>scan_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?=&&)|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_parser'>parser</span><span class='period'>.</span><span class='id identifier rubyid_skip_until'>skip_until</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>&&|\Z</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@version</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='comma'>,</span> <span class='const'>Versionomy</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>break</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser'>check_capable_browser</span>
<span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_engines'>check_capable_browser_engines</span>
<span class='id identifier rubyid_chrome?'>chrome?</span> <span class='op'>||</span> <span class='id identifier rubyid_safari?'>safari?</span> <span class='op'>||</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_check_capable_browser_recents'>check_capable_browser_recents</span>
<span class='lparen'>(</span><span class='id identifier rubyid_firefox?'>firefox?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>28</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_msie?'>msie?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>10</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_opera?'>opera?</span> <span class='op'>&&</span> <span class='ivar'>@version</span> <span class='op'>>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>15</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># :nodoc:
</span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_version_token'>parse_version_token</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_mo'>mo</span> <span class='op'>=</span> <span class='const'>VERSION_TOKEN</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_token'>token</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid version check: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_token'>token</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_mo'>mo</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>operator</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mo'>mo</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>version</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="accepts?-instance_method">
- (<tt>Boolean</tt>) <strong>accepts?</strong>(*languages)
</h3><div class="docstring">
<div class="discussion">
<p>Checks if the browser accepts a specific language or languages.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>languages</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The list of languages.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p><code>true</code> if at least one of requested languages is accepted, <code>false</code> otherwise.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
69
70
71
72</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 69</span>
<span class='kw'>def</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='id identifier rubyid_languages'>languages</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='ivar'>@languages</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span> <span class='op'>&</span> <span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="classes-instance_method">
- (<tt>String|Array</tt>) <strong>classes</strong>(join = " ", name: true, version: true, platform: true)
<span class="aliases">Also known as:
<span class="names"><span id='meta-instance_method'>meta</span>, <span id='to_s-instance_method'>to_s</span></span>
</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.</p>
<p>For version, it will be included a class for every token of the version. For example, version <code>7.0.1.2</code> will return this:</p>
<p><code>ruby
["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]
</code></p>
<p>If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>join</span>
<span class='type'>(<tt>String|NilClass</tt>)</span>
<em class="default">(defaults to: <tt>" "</tt>)</em>
—
<div class='inline'><p>If non falsy, the separator to use to join information. If falsy, informations will be returned as array.</p>
</div>
</li>
<li>
<span class='name'>name</span>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p>If non falsy, the string to prepend to the name. If falsy, the name information will not be included.</p>
</div>
</li>
<li>
<span class='name'>version</span>
<span class='type'>(<tt>String|NilClass</tt>)</span>
—
<div class='inline'><p>If non falsy, the string to prepend to the version. If falsy, the version information will not be included.</p>
</div>
</li>
<li>
<span class='name'>platform</span>
<span class='type'>(<tt>String|NilClass</tt>)</span>
—
<div class='inline'><p>If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String|Array</tt>)</span>
—
<div class='inline'><p>CSS ready information of the current browser.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
58
59
60
61</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 58</span>
<span class='kw'>def</span> <span class='id identifier rubyid_classes'>classes</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>name:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_name_to_str'>name_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_version_to_str'>version_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_platform_to_str'>platform_to_str</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span>
<span class='id identifier rubyid_join'>join</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_join'>join</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="is?-instance_method">
- (<tt>Boolean</tt>) <strong>is?</strong>(name: nil, engine: nil, version: nil, platform: nil, languages: nil)
</h3><div class="docstring">
<div class="discussion">
<p>Checks if the browser matches a specific query.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>name</span>
<span class='type'>(<tt>Symbol|Array|NilClass</tt>)</span>
—
<div class='inline'><p>The list of names to check. Also, this meta-name is supported: <code>:tablet</code>.</p>
</div>
</li>
<li>
<span class='name'>engine</span>
<span class='type'>(<tt>Symbol|Array|NilClass</tt>)</span>
—
<div class='inline'><p>Alias for <code>name</code>, <strong>which has precedence over this.</strong></p>
</div>
</li>
<li>
<span class='name'>version</span>
<span class='type'>(<tt>String|NilClass</tt>)</span>
—
<div class='inline'><p>The query to match the version.
It must be a query in the form is <code>OPERATOR VALUE && ..</code>, where <code>OPERATOR</code> is one of <code>["<", "<=", "=", "==", ">=", ">"]</code>.
You can also pass the value “capable”, which will return true for Webkit browsers, IE 10 or above, Firefox 28 and above and Opera 15 and above.</p>
</div>
</li>
<li>
<span class='name'>platform</span>
<span class='type'>(<tt>Symbol|Array|NilClass</tt>)</span>
—
<div class='inline'><p>The list of platforms to check.</p>
</div>
</li>
<li>
<span class='name'>languages</span>
<span class='type'>(<tt>Symbol|Array|NilClass</tt>)</span>
—
<div class='inline'><p>The list of languages to check.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p><code>true</code> if browser match the query, <code>false</code> otherwise.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
84
85
86
87
88
89
90
91</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 84</span>
<span class='kw'>def</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>name:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>engine:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>version:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>platform:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>languages:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_name'>name</span> <span class='op'>||=</span> <span class='id identifier rubyid_engine'>engine</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='ivar'>@name</span> <span class='op'>==</span> <span class='id identifier rubyid_apply_aliases'>apply_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>true</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_query_version'>query_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_version'>version</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='ivar'>@platform</span> <span class='op'>==</span> <span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_platform'>platform</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>&&=</span> <span class='id identifier rubyid_accepts?'>accepts?</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_query_arguments'>normalize_query_arguments</span><span class='lparen'>(</span><span class='id identifier rubyid_languages'>languages</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_languages'>languages</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="supported?-instance_method">
- (<tt>Boolean</tt>) <strong>supported?</strong>(browsers = {})
</h3><div class="docstring">
<div class="discussion">
<p>Check if the browser is supported.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>browsers</span>
<span class='type'>(<tt>Hash|String</tt>)</span>
<em class="default">(defaults to: <tt>{}</tt>)</em>
—
<div class='inline'><p>A map of name and minimum supported major version, or a path to YAML file containing the map.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
—
<div class='inline'><p><code>true</code> if current browser is supported, <code>false</code> otherwise. If the name is not found in the map, <code>false</code> is returned.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
97
98
99
100
101</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/brauser/browser.rb', line 97</span>
<span class='kw'>def</span> <span class='id identifier rubyid_supported?'>supported?</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id identifier rubyid_browsers'>browsers</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='kw'>unless</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>=</span> <span class='id identifier rubyid_browsers'>browsers</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_minimum_version'>minimum_version</span> <span class='op'>?</span> <span class='id identifier rubyid_is?'>is?</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>>= </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_minimum_version'>minimum_version</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>false</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Aug 18 15:49:54 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
</div>
</body>
</html>