browser 5.3.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/{FUNDING.yml → .github/FUNDING.yml} +2 -1
  3. data/.github/workflows/{tests.yml → ruby-tests.yml} +17 -17
  4. data/.rubocop.yml +3 -23
  5. data/CHANGELOG.md +10 -0
  6. data/LICENSE.md +20 -0
  7. data/README.md +10 -3
  8. data/bots.yml +0 -1
  9. data/browser.gemspec +4 -5
  10. data/gemfiles/{rails5.gemfile → 7_0.gemfile} +1 -1
  11. data/gemfiles/{rails6.gemfile → 7_1.gemfile} +1 -1
  12. data/lib/browser/accept_language.rb +1 -1
  13. data/lib/browser/base.rb +34 -29
  14. data/lib/browser/browser.rb +4 -3
  15. data/lib/browser/chrome.rb +4 -0
  16. data/lib/browser/device.rb +9 -9
  17. data/lib/browser/edge.rb +1 -1
  18. data/lib/browser/meta/base.rb +1 -1
  19. data/lib/browser/platform.rb +1 -1
  20. data/lib/browser/testing.rb +3 -3
  21. data/lib/browser/version.rb +1 -1
  22. data/lib/browser.rb +1 -1
  23. data/search_engines.yml +1 -0
  24. data/test/browser_test.rb +3 -3
  25. data/test/rails_test.rb +1 -1
  26. data/test/test_helper.rb +4 -2
  27. data/test/ua.yml +5 -0
  28. data/test/ua_bots.yml +0 -1
  29. data/test/unit/accept_language_test.rb +1 -1
  30. data/test/unit/android_app_test.rb +3 -3
  31. data/test/unit/android_test.rb +17 -17
  32. data/test/unit/blackberry_test.rb +1 -1
  33. data/test/unit/bots_test.rb +15 -4
  34. data/test/unit/chrome_test.rb +1 -0
  35. data/test/unit/device_test.rb +25 -25
  36. data/test/unit/edge_test.rb +6 -0
  37. data/test/unit/electron_test.rb +1 -1
  38. data/test/unit/facebook_test.rb +3 -3
  39. data/test/unit/generic_test.rb +3 -3
  40. data/test/unit/instagram_test.rb +2 -2
  41. data/test/unit/internet_explorer_test.rb +18 -18
  42. data/test/unit/ios_app_test.rb +3 -3
  43. data/test/unit/ios_test.rb +12 -12
  44. data/test/unit/kindle_test.rb +15 -0
  45. data/test/unit/meta_test.rb +13 -13
  46. data/test/unit/platform_test.rb +33 -25
  47. data/test/unit/proxy_test.rb +2 -2
  48. data/test/unit/safari_test.rb +14 -9
  49. data/test/unit/snapchat_test.rb +3 -3
  50. data/test/unit/uc_browser_test.rb +1 -1
  51. data/test/unit/windows_test.rb +11 -11
  52. metadata +12 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 972b76e90909836598cc70314c1608eeba4c4db13947bca76e4a350dc83cb741
4
- data.tar.gz: 4d1d0f4bb18d2b57e82b91f04cfe6dfda5e02ea0fb967c12c87c3ad293a556c7
3
+ metadata.gz: 955928c52746af052fa9e4acb5555ba3d438326670ee5b587f7a66eff89193f5
4
+ data.tar.gz: a9a9a822b3dcac0fa8b5a1f946e60c1c4eef3bc2801c41b990b33c496bb635ed
5
5
  SHA512:
6
- metadata.gz: 2ae9b28f091921ffa7092ebe434cb5d518dc8fad41743af8f94c2240729379a44057d351da4beb5c5b5daade4a809deef13099e93ce222e4a43d419a2b791400
7
- data.tar.gz: 7722b7ea98e7d8d870fbb4abb75128677db755423287d3930f5c09680316bd376a7fe18c500080d2314c29eec446b7b9927844e13c49ba687dcb5b447e311d94
6
+ metadata.gz: b35967db554e9dc880c4998418fde96e2fd8c75283ebc9549c948754ce9b9b383fc5977cfe1008ae176e4e00c7ecf1318d0ed8bc31f987ed19aaef294cbb669b
7
+ data.tar.gz: 845a5a586f88a402f967a1c5ce43cdb3f736c33aa78288e23972f4ee14e07d81fa805bef169000979d14dcb9d24299ef008d452c29c04b88b50e3516f76b3baf
@@ -1,3 +1,4 @@
1
1
  # These are supported funding model platforms
2
-
2
+ ---
3
3
  github: [fnando]
4
+ custom: ["https://paypal.me/nandovieira/🍕"]
@@ -1,48 +1,47 @@
1
- name: Tests
1
+ ---
2
+ name: ruby-tests
2
3
 
3
4
  on:
4
- pull_request:
5
- branches:
6
- - main
5
+ pull_request_target:
7
6
  push:
8
7
  branches:
9
8
  - main
10
-
11
- schedule:
12
- - cron: "0 10 * * *"
9
+ workflow_dispatch:
10
+ inputs: {}
13
11
 
14
12
  jobs:
15
13
  build:
16
14
  name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
17
15
  runs-on: "ubuntu-latest"
16
+ if: |
17
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
18
+ github.actor != 'dependabot[bot]'
18
19
  strategy:
19
20
  fail-fast: false
20
21
  matrix:
21
- ruby: ["2.7.x", "2.6.x", "2.5.x"]
22
+ ruby: ["3.2", "3.3"]
22
23
  gemfile:
23
24
  - Gemfile
24
- - gemfiles/rails5.gemfile
25
- - gemfiles/rails6.gemfile
25
+ - gemfiles/7_1.gemfile
26
+ - gemfiles/6_1.gemfile
26
27
 
27
28
  steps:
28
- - uses: actions/checkout@v1
29
+ - uses: actions/checkout@v2.4.0
29
30
 
30
31
  - uses: actions/cache@v2
31
32
  with:
32
33
  path: vendor/bundle
33
34
  key: >
34
- ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }}
35
- restore-keys: >
36
- ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }}
35
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
36
+ hashFiles(matrix.gemfile) }}
37
37
 
38
38
  - name: Set up Ruby
39
- uses: actions/setup-ruby@v1
39
+ uses: ruby/setup-ruby@v1
40
40
  with:
41
41
  ruby-version: ${{ matrix.ruby }}
42
42
 
43
43
  - name: Install gem dependencies
44
44
  env:
45
- RAILS_ENV: test
46
45
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
47
46
  run: |
48
47
  gem install bundler
@@ -51,7 +50,8 @@ jobs:
51
50
 
52
51
  - name: Run Tests
53
52
  env:
54
- RAILS_ENV: test
53
+ PGHOST: localhost
54
+ PGUSER: postgres
55
55
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
56
56
  run: |
57
57
  bundle exec rake
data/.rubocop.yml CHANGED
@@ -4,6 +4,7 @@ inherit_gem:
4
4
 
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.5
7
+ NewCops: enable
7
8
  Exclude:
8
9
  - bin/**/*
9
10
  - gemfiles/**/*
@@ -13,29 +14,8 @@ AllCops:
13
14
  - "*.gemspec"
14
15
  - config.ru
15
16
 
16
- Metrics/ClassLength:
17
- Enabled: false
18
-
19
- Layout/LineLength:
20
- Max: 80
21
-
22
- Metrics/MethodLength:
23
- Enabled: false
24
-
25
- Style/Alias:
26
- EnforcedStyle: prefer_alias_method
27
-
28
- Lint/RedundantCopDisableDirective:
29
- Enabled: false
30
-
31
- Metrics/AbcSize:
32
- Enabled: false
33
-
34
- Metrics/CyclomaticComplexity:
35
- Enabled: false
36
-
37
- Metrics/PerceivedComplexity:
17
+ Naming/VariableNumber:
38
18
  Enabled: false
39
19
 
40
- Naming/VariableNumber:
20
+ Minitest/EmptyLineBeforeAssertionMethods:
41
21
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.0
4
+
5
+ - Add `Browser::Base#chromium_based?`.
6
+ - Change how browser detection works to avoid re-instantiating classes.
7
+ - Bump up minimum required ruby version to 3.2.0.
8
+
9
+ ## 5.3.1
10
+
11
+ - Remove Stripe webhooks from bot list.
12
+
3
13
  ## 5.3.0
4
14
 
5
15
  - Bump up minimum required ruby version to 2.5.0. We're now relying on
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2010 Nando Vieira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Browser
2
2
 
3
- [![Tests](https://github.com/fnando/browser/workflows/Tests/badge.svg)](https://github.com/fnando/browser)
4
- [![Code Climate](https://codeclimate.com/github/fnando/browser/badges/gpa.svg)](https://codeclimate.com/github/fnando/browser)
3
+ [![Tests](https://github.com/fnando/browser/workflows/ruby-tests/badge.svg)](https://github.com/fnando/browser)
5
4
  [![Gem](https://img.shields.io/gem/v/browser.svg)](https://rubygems.org/gems/browser)
6
5
  [![Gem](https://img.shields.io/gem/dt/browser.svg)](https://rubygems.org/gems/browser)
7
6
 
@@ -23,6 +22,7 @@ browser = Browser.new("Some User Agent", accept_language: "en-us")
23
22
  # General info
24
23
  browser.bot?
25
24
  browser.chrome?
25
+ browser.chromium_based?
26
26
  browser.core_media?
27
27
  browser.duck_duck_go?
28
28
  browser.edge? # Newest MS browser
@@ -53,7 +53,6 @@ browser.yandex?
53
53
  browser.wechat?
54
54
  browser.qq?
55
55
  browser.weibo?
56
- browser.yandex?
57
56
  browser.sputnik?
58
57
  browser.sougou_browser?
59
58
 
@@ -323,6 +322,14 @@ Browser::Bot.matchers.delete(Browser::Bot::KeywordMatcher)
323
322
  Browser::Bot.matchers.delete(Browser::Bot::EmptyUserAgentMatcher)
324
323
  ```
325
324
 
325
+ To extend the bot list, you can manipulate the methods below:
326
+
327
+ ```ruby
328
+ Browser::Bot.bots.merge!(new_bots_hash)
329
+ Browser::Bot.bot_exceptions += new_exceptions
330
+ Browser::Bot.search_engines.merge!(new_search_engines_hash)
331
+ ```
332
+
326
333
  ### Middleware
327
334
 
328
335
  You can use the `Browser::Middleware` to redirect user agents.
data/bots.yml CHANGED
@@ -232,7 +232,6 @@ spinn3r: Spinn3r aggregator
232
232
  sputnikbot: SputnikBot
233
233
  squider: Squider
234
234
  statuscake: StatusCake
235
- stripe: Stripe
236
235
  swiftbot: Swiftype Bot
237
236
  tangibleebot: TangibleeBot
238
237
  teeraid: TeeRaidBot
data/browser.gemspec CHANGED
@@ -7,27 +7,26 @@ Gem::Specification.new do |s|
7
7
  s.version = Browser::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Nando Vieira"]
10
- s.email = ["fnando.vieira@gmail.com"]
10
+ s.email = ["me@fnando.com"]
11
11
  s.homepage = "https://github.com/fnando/browser"
12
12
  s.summary = "Do some browser detection with Ruby."
13
13
  s.description = s.summary
14
14
  s.license = "MIT"
15
- s.required_ruby_version = ">= 2.5.0"
15
+ s.required_ruby_version = ">= 3.2.0"
16
16
 
17
+ s.metadata["rubygems_mfa_required"] = "true"
17
18
  s.metadata["changelog_uri"] = "https://github.com/fnando/browser/blob/main/CHANGELOG.md"
18
19
 
19
20
  s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  s.executables = `git ls-files -- exe/*`
22
22
  .split("\n")
23
23
  .map {|f| File.basename(f) }
24
24
  s.require_paths = ["lib"]
25
25
 
26
- s.add_development_dependency "bundler", ">= 0"
26
+ s.add_development_dependency "bundler"
27
27
  s.add_development_dependency "minitest"
28
28
  s.add_development_dependency "minitest-autotest"
29
29
  s.add_development_dependency "minitest-utils"
30
- s.add_development_dependency "pry-meta"
31
30
  s.add_development_dependency "rack-test"
32
31
  s.add_development_dependency "rails"
33
32
  s.add_development_dependency "rake"
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 5.0"
6
+ gem "rails", "~> 7.0.0"
@@ -3,4 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec path: ".."
5
5
 
6
- gem "rails", "~> 6.0"
6
+ gem "rails", "~> 7.1.0"
@@ -55,7 +55,7 @@ module Browser
55
55
 
56
56
  private def quality_value
57
57
  qvalue = part[/;q=([\d.]+)/, 1]
58
- qvalue = /\A0\.0?\z/.match?(qvalue) ? "0.0" : qvalue
58
+ qvalue = "0.0" if /\A0\.0?\z/.match?(qvalue)
59
59
  qvalue = qvalue.squeeze(".") if qvalue
60
60
  qvalue
61
61
  end
data/lib/browser/base.rb CHANGED
@@ -26,7 +26,7 @@ module Browser
26
26
  end
27
27
  end
28
28
 
29
- alias_method :to_a, :meta
29
+ alias to_a meta
30
30
 
31
31
  # Return meta representation as string.
32
32
  def to_s
@@ -59,13 +59,13 @@ module Browser
59
59
 
60
60
  # Detect if browser is Microsoft Internet Explorer.
61
61
  def ie?(expected_version = nil)
62
- InternetExplorer.new(ua).match? &&
62
+ instance_of?(InternetExplorer) &&
63
63
  detect_version?(full_version, expected_version)
64
64
  end
65
65
 
66
66
  # Detect if browser is Microsoft Edge.
67
67
  def edge?(expected_version = nil)
68
- Edge.new(ua).match? && detect_version?(full_version, expected_version)
68
+ instance_of?(Edge) && detect_version?(full_version, expected_version)
69
69
  end
70
70
 
71
71
  def compatibility_view?
@@ -82,32 +82,32 @@ module Browser
82
82
 
83
83
  # Detect if browser is Instagram.
84
84
  def instagram?(expected_version = nil)
85
- Instagram.new(ua).match? &&
85
+ instance_of?(Instagram) &&
86
86
  detect_version?(full_version, expected_version)
87
87
  end
88
88
 
89
89
  # Detect if browser is Snapchat.
90
90
  def snapchat?(expected_version = nil)
91
- Snapchat.new(ua).match? &&
91
+ instance_of?(Snapchat) &&
92
92
  detect_version?(full_version, expected_version)
93
93
  end
94
94
 
95
95
  # Detect if browser if Facebook.
96
96
  def facebook?(expected_version = nil)
97
- Facebook.new(ua).match? &&
97
+ instance_of?(Facebook) &&
98
98
  detect_version?(full_version, expected_version)
99
99
  end
100
100
 
101
101
  # Detect if browser is Otter.
102
102
  def otter?(expected_version = nil)
103
- Otter.new(ua).match? &&
103
+ instance_of?(Otter) &&
104
104
  detect_version?(full_version, expected_version)
105
105
  end
106
106
 
107
107
  # Detect if browser is WebKit-based.
108
108
  def webkit?(expected_version = nil)
109
109
  ua.match?(/AppleWebKit/i) &&
110
- (!edge? || Edge.new(ua).chrome_based?) &&
110
+ (!edge? || chromium_based?) &&
111
111
  detect_version?(webkit_full_version, expected_version)
112
112
  end
113
113
 
@@ -124,13 +124,13 @@ module Browser
124
124
 
125
125
  # Detect if browser is PhantomJS
126
126
  def phantom_js?(expected_version = nil)
127
- PhantomJS.new(ua).match? &&
127
+ instance_of?(PhantomJS) &&
128
128
  detect_version?(full_version, expected_version)
129
129
  end
130
130
 
131
131
  # Detect if browser is Safari.
132
132
  def safari?(expected_version = nil)
133
- Safari.new(ua).match? && detect_version?(full_version, expected_version)
133
+ instance_of?(Safari) && detect_version?(full_version, expected_version)
134
134
  end
135
135
 
136
136
  def safari_webapp_mode?
@@ -139,55 +139,55 @@ module Browser
139
139
 
140
140
  # Detect if browser is Firefox.
141
141
  def firefox?(expected_version = nil)
142
- Firefox.new(ua).match? && detect_version?(full_version, expected_version)
142
+ instance_of?(Firefox) && detect_version?(full_version, expected_version)
143
143
  end
144
144
 
145
145
  # Detect if browser is Chrome.
146
146
  def chrome?(expected_version = nil)
147
- Chrome.new(ua).match? && detect_version?(full_version, expected_version)
147
+ instance_of?(Chrome) && detect_version?(full_version, expected_version)
148
148
  end
149
149
 
150
150
  # Detect if browser is Opera.
151
151
  def opera?(expected_version = nil)
152
- Opera.new(ua).match? && detect_version?(full_version, expected_version)
152
+ instance_of?(Opera) && detect_version?(full_version, expected_version)
153
153
  end
154
154
 
155
155
  # Detect if browser is Sputnik.
156
156
  def sputnik?(expected_version = nil)
157
- Sputnik.new(ua).match? && detect_version?(full_version, expected_version)
157
+ instance_of?(Sputnik) && detect_version?(full_version, expected_version)
158
158
  end
159
159
 
160
160
  # Detect if browser is Yandex.
161
161
  def yandex?(expected_version = nil)
162
- Yandex.new(ua).match? && detect_version?(full_version, expected_version)
162
+ instance_of?(Yandex) && detect_version?(full_version, expected_version)
163
163
  end
164
- alias_method :yandex_browser?, :yandex?
164
+ alias yandex_browser? yandex?
165
165
 
166
166
  # Detect if browser is UCBrowser.
167
167
  def uc_browser?(expected_version = nil)
168
- UCBrowser.new(ua).match? &&
168
+ instance_of?(UCBrowser) &&
169
169
  detect_version?(full_version, expected_version)
170
170
  end
171
171
 
172
172
  # Detect if browser is Nokia S40 Ovi Browser.
173
173
  def nokia?(expected_version = nil)
174
- Nokia.new(ua).match? && detect_version?(full_version, expected_version)
174
+ instance_of?(Nokia) && detect_version?(full_version, expected_version)
175
175
  end
176
176
 
177
177
  # Detect if browser is MicroMessenger.
178
178
  def micro_messenger?(expected_version = nil)
179
- MicroMessenger.new(ua).match? &&
179
+ instance_of?(MicroMessenger) &&
180
180
  detect_version?(full_version, expected_version)
181
181
  end
182
182
 
183
- alias_method :wechat?, :micro_messenger?
183
+ alias wechat? micro_messenger?
184
184
 
185
185
  def weibo?(expected_version = nil)
186
- Weibo.new(ua).match? && detect_version?(full_version, expected_version)
186
+ instance_of?(Weibo) && detect_version?(full_version, expected_version)
187
187
  end
188
188
 
189
189
  def alipay?(expected_version = nil)
190
- Alipay.new(ua).match? && detect_version?(full_version, expected_version)
190
+ instance_of?(Alipay) && detect_version?(full_version, expected_version)
191
191
  end
192
192
 
193
193
  # Detect if browser is Opera Mini.
@@ -210,29 +210,29 @@ module Browser
210
210
 
211
211
  # Detect if browser is Huawei.
212
212
  def huawei_browser?(expected_version = nil)
213
- HuaweiBrowser.new(ua).match? &&
213
+ instance_of?(HuaweiBrowser) &&
214
214
  detect_version?(full_version, expected_version)
215
215
  end
216
216
 
217
217
  # Detect if browser is Xiaomi Miui.
218
218
  def miui_browser?(expected_version = nil)
219
- MiuiBrowser.new(ua).match? &&
219
+ instance_of?(MiuiBrowser) &&
220
220
  detect_version?(full_version, expected_version)
221
221
  end
222
222
 
223
223
  # Detect if browser is Maxthon.
224
224
  def maxthon?(expected_version = nil)
225
- Maxthon.new(ua).match? && detect_version?(full_version, expected_version)
225
+ instance_of?(Maxthon) && detect_version?(full_version, expected_version)
226
226
  end
227
227
 
228
228
  # Detect if browser is QQ.
229
229
  def qq?(expected_version = nil)
230
- QQ.new(ua).match? && detect_version?(full_version, expected_version)
230
+ instance_of?(QQ) && detect_version?(full_version, expected_version)
231
231
  end
232
232
 
233
233
  # Detect if browser is Sougou.
234
234
  def sougou_browser?(expected_version = nil)
235
- SougouBrowser.new(ua).match? &&
235
+ instance_of?(SougouBrowser) &&
236
236
  detect_version?(full_version, expected_version)
237
237
  end
238
238
 
@@ -241,6 +241,11 @@ module Browser
241
241
  ua.include?("GSA") && detect_version?(full_version, expected_version)
242
242
  end
243
243
 
244
+ # Detect if browser is Chromium-based.
245
+ def chromium_based?
246
+ false
247
+ end
248
+
244
249
  def webkit_full_version
245
250
  ua[%r{AppleWebKit/([\d.]+)}, 1] || "0.0"
246
251
  end
@@ -260,12 +265,12 @@ module Browser
260
265
 
261
266
  # Detect if the browser is Electron.
262
267
  def electron?(expected_version = nil)
263
- Electron.new(ua).match? && detect_version?(full_version, expected_version)
268
+ instance_of?(Electron) && detect_version?(full_version, expected_version)
264
269
  end
265
270
 
266
271
  private def validate_size(subject, input)
267
272
  actual_bytesize = input.bytesize
268
- size_limit = Browser.public_send("#{subject}_size_limit")
273
+ size_limit = Browser.public_send(:"#{subject}_size_limit")
269
274
 
270
275
  return if actual_bytesize < size_limit
271
276
 
@@ -101,8 +101,9 @@ module Browser
101
101
  end
102
102
 
103
103
  def self.new(user_agent, **kwargs)
104
- matchers
105
- .map {|klass| klass.new(user_agent || EMPTY_STRING, **kwargs) }
106
- .find(&:match?)
104
+ matchers.each do |matcher_class|
105
+ matcher = matcher_class.new(user_agent || EMPTY_STRING, **kwargs)
106
+ return matcher if matcher.match?
107
+ end
107
108
  end
108
109
  end
@@ -19,6 +19,10 @@ module Browser
19
19
  "0.0"
20
20
  end
21
21
 
22
+ def chromium_based?
23
+ true
24
+ end
25
+
22
26
  def match?
23
27
  ua.match?(/Chrome|CriOS/) &&
24
28
  !ua.match?(/PhantomJS|FxiOS|ArchiveBot/) &&
@@ -96,7 +96,7 @@ module Browser
96
96
  def ipod_touch?
97
97
  id == :ipod_touch
98
98
  end
99
- alias_method :ipod?, :ipod_touch?
99
+ alias ipod? ipod_touch?
100
100
 
101
101
  def iphone?
102
102
  id == :iphone
@@ -105,12 +105,12 @@ module Browser
105
105
  def ps3?
106
106
  id == :ps3
107
107
  end
108
- alias_method :playstation3?, :ps3?
108
+ alias playstation3? ps3?
109
109
 
110
110
  def ps4?
111
111
  id == :ps4
112
112
  end
113
- alias_method :playstation4?, :ps4?
113
+ alias playstation4? ps4?
114
114
 
115
115
  def psp?
116
116
  id == :psp
@@ -119,8 +119,8 @@ module Browser
119
119
  def playstation_vita?
120
120
  id == :psvita
121
121
  end
122
- alias_method :vita?, :playstation_vita?
123
- alias_method :psp_vita?, :playstation_vita?
122
+ alias vita? playstation_vita?
123
+ alias psp_vita? playstation_vita?
124
124
 
125
125
  def kindle?
126
126
  id == :kindle || kindle_fire?
@@ -133,22 +133,22 @@ module Browser
133
133
  def nintendo_wii?
134
134
  id == :wii
135
135
  end
136
- alias_method :wii?, :nintendo_wii?
136
+ alias wii? nintendo_wii?
137
137
 
138
138
  def nintendo_wiiu?
139
139
  id == :wiiu
140
140
  end
141
- alias_method :wiiu?, :nintendo_wiiu?
141
+ alias wiiu? nintendo_wiiu?
142
142
 
143
143
  def nintendo_switch?
144
144
  id == :switch
145
145
  end
146
- alias_method :switch?, :nintendo_switch?
146
+ alias switch? nintendo_switch?
147
147
 
148
148
  def blackberry_playbook?
149
149
  id == :playbook
150
150
  end
151
- alias_method :playbook?, :blackberry_playbook?
151
+ alias playbook? blackberry_playbook?
152
152
 
153
153
  def surface?
154
154
  id == :surface
data/lib/browser/edge.rb CHANGED
@@ -18,7 +18,7 @@ module Browser
18
18
  ua.match?(%r{((?:Edge|Edg|EdgiOS|EdgA)/[\d.]+|Trident/8)})
19
19
  end
20
20
 
21
- def chrome_based?
21
+ def chromium_based?
22
22
  match? && ua.match?(/\bEdg\b/)
23
23
  end
24
24
  end
@@ -37,7 +37,7 @@ module Browser
37
37
  end
38
38
 
39
39
  def to_a
40
- meta.to_s.squeeze(" ").split(" ")
40
+ meta.to_s.squeeze(" ").split
41
41
  end
42
42
  end
43
43
  end
@@ -138,7 +138,7 @@ module Browser
138
138
  def android_app?
139
139
  android? && ua.match?(/\bwv\b/)
140
140
  end
141
- alias_method :android_webview?, :android_app?
141
+ alias android_webview? android_app?
142
142
 
143
143
  # http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
144
144
  def windows_xp?
@@ -16,9 +16,9 @@ module Browser
16
16
  end
17
17
 
18
18
  def self.search_engine_user_agents
19
- @search_engine_user_agents ||= begin
20
- YAML.load_file(Browser.root.join("test/ua_search_engines.yml"))
21
- end
19
+ @search_engine_user_agents ||= YAML.load_file(
20
+ Browser.root.join("test/ua_search_engines.yml")
21
+ )
22
22
  end
23
23
 
24
24
  def self.[](key)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Browser
4
- VERSION = "5.3.0"
4
+ VERSION = "6.0.0"
5
5
  end
data/lib/browser.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "browser/browser"
4
- require_relative "browser/rails" if defined?(::Rails)
4
+ require_relative "browser/rails" if defined?(Rails)
data/search_engines.yml CHANGED
@@ -1,3 +1,4 @@
1
+ ---
1
2
  ask jeeves: "Ask Jeeves"
2
3
  baidu: "Chinese search engine"
3
4
  bingbot: "Microsoft bing bot"
data/test/browser_test.rb CHANGED
@@ -8,7 +8,7 @@ class BrowserTest < Minitest::Test
8
8
  assert_equal "Safari", browser.ua
9
9
  end
10
10
 
11
- test "don't fail with nil user agent" do
11
+ test "does not fail with nil user agent" do
12
12
  browser = Browser.new(nil)
13
13
  refute browser.known?
14
14
  end
@@ -25,7 +25,7 @@ class BrowserTest < Minitest::Test
25
25
  Safari
26
26
  UCBrowser
27
27
  ].each do |ua|
28
- test "don't fail when have no version info (#{ua})" do
28
+ test "does not fail when have no version info (#{ua})" do
29
29
  browser = Browser.new(ua)
30
30
  assert_equal "0", browser.version
31
31
  assert_equal "0.0", browser.full_version
@@ -117,7 +117,7 @@ class BrowserTest < Minitest::Test
117
117
 
118
118
  test "returns empty language set for missing accept language" do
119
119
  browser = Browser.new("")
120
- assert_equal [], browser.accept_language
120
+ assert_empty browser.accept_language
121
121
  end
122
122
 
123
123
  test "sets accept language while instantiating object" do