browser 2.7.1 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +1 -1
  3. data/.github/workflows/tests.yml +57 -0
  4. data/.gitignore +1 -0
  5. data/.prettierignore +1 -0
  6. data/.rubocop.yml +13 -1
  7. data/CHANGELOG.md +122 -13
  8. data/FUNDING.yml +3 -0
  9. data/README.md +134 -88
  10. data/Rakefile +8 -1
  11. data/bot_exceptions.yml +1 -0
  12. data/bots.yml +300 -293
  13. data/browser.gemspec +4 -1
  14. data/gemfiles/{rails5.gemfile → rails6_1.gemfile} +1 -1
  15. data/lib/browser/accept_language.rb +4 -4
  16. data/lib/browser/aliases.rb +1 -1
  17. data/lib/browser/alipay.rb +1 -1
  18. data/lib/browser/base.rb +82 -18
  19. data/lib/browser/blackberry.rb +1 -1
  20. data/lib/browser/bot/empty_user_agent_matcher.rb +11 -0
  21. data/lib/browser/bot/keyword_matcher.rb +11 -0
  22. data/lib/browser/bot/known_bots_matcher.rb +11 -0
  23. data/lib/browser/bot.rb +34 -26
  24. data/lib/browser/browser.rb +59 -56
  25. data/lib/browser/chrome.rb +13 -3
  26. data/lib/browser/device/android.rb +1 -1
  27. data/lib/browser/device/blackberry_playbook.rb +1 -1
  28. data/lib/browser/device/ipad.rb +1 -1
  29. data/lib/browser/device/iphone.rb +1 -1
  30. data/lib/browser/device/ipod_touch.rb +1 -1
  31. data/lib/browser/device/kindle.rb +1 -1
  32. data/lib/browser/device/kindle_fire.rb +1 -1
  33. data/lib/browser/device/playstation3.rb +1 -1
  34. data/lib/browser/device/playstation4.rb +1 -1
  35. data/lib/browser/device/psp.rb +1 -1
  36. data/lib/browser/device/psvita.rb +1 -1
  37. data/lib/browser/device/samsung.rb +33 -0
  38. data/lib/browser/device/surface.rb +1 -1
  39. data/lib/browser/device/switch.rb +1 -1
  40. data/lib/browser/device/tv.rb +1 -1
  41. data/lib/browser/device/unknown.rb +1 -1
  42. data/lib/browser/device/wii.rb +1 -1
  43. data/lib/browser/device/wiiu.rb +1 -1
  44. data/lib/browser/device/xbox_360.rb +1 -1
  45. data/lib/browser/device/xbox_one.rb +1 -1
  46. data/lib/browser/device.rb +37 -27
  47. data/lib/browser/duck_duck_go.rb +22 -0
  48. data/lib/browser/edge.rb +3 -3
  49. data/lib/browser/electron.rb +1 -1
  50. data/lib/browser/facebook.rb +1 -1
  51. data/lib/browser/firefox.rb +1 -1
  52. data/lib/browser/google_search_app.rb +21 -0
  53. data/lib/browser/huawei_browser.rb +21 -0
  54. data/lib/browser/instagram.rb +1 -1
  55. data/lib/browser/internet_explorer.rb +2 -2
  56. data/lib/browser/maxthon.rb +21 -0
  57. data/lib/browser/meta/base.rb +0 -1
  58. data/lib/browser/meta.rb +12 -13
  59. data/lib/browser/micro_messenger.rb +1 -1
  60. data/lib/browser/middleware/context/additions.rb +1 -1
  61. data/lib/browser/middleware.rb +1 -1
  62. data/lib/browser/miui_browser.rb +21 -0
  63. data/lib/browser/nokia.rb +1 -1
  64. data/lib/browser/opera.rb +1 -1
  65. data/lib/browser/otter.rb +1 -1
  66. data/lib/browser/phantom_js.rb +1 -1
  67. data/lib/browser/platform/adobe_air.rb +1 -1
  68. data/lib/browser/platform/android.rb +1 -1
  69. data/lib/browser/platform/base.rb +3 -2
  70. data/lib/browser/platform/blackberry.rb +1 -1
  71. data/lib/browser/platform/chrome_os.rb +1 -1
  72. data/lib/browser/platform/firefox_os.rb +1 -1
  73. data/lib/browser/platform/ios.rb +2 -2
  74. data/lib/browser/platform/kai_os.rb +23 -0
  75. data/lib/browser/platform/linux.rb +1 -1
  76. data/lib/browser/platform/mac.rb +5 -3
  77. data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
  78. data/lib/browser/platform/windows.rb +2 -2
  79. data/lib/browser/platform/windows_mobile.rb +1 -1
  80. data/lib/browser/platform/windows_phone.rb +1 -1
  81. data/lib/browser/platform.rb +37 -28
  82. data/lib/browser/qq.rb +1 -1
  83. data/lib/browser/rails.rb +3 -3
  84. data/lib/browser/safari.rb +16 -1
  85. data/lib/browser/samsung_browser.rb +21 -0
  86. data/lib/browser/snapchat.rb +1 -1
  87. data/lib/browser/sougou_browser.rb +24 -0
  88. data/lib/browser/sputnik.rb +2 -5
  89. data/lib/browser/uc_browser.rb +1 -1
  90. data/lib/browser/{generic.rb → unknown.rb} +3 -3
  91. data/lib/browser/version.rb +1 -1
  92. data/lib/browser/weibo.rb +1 -1
  93. data/lib/browser/yandex.rb +1 -1
  94. data/lib/browser.rb +2 -2
  95. data/samsung.yml +138 -0
  96. data/test/browser_test.rb +37 -10
  97. data/test/test_helper.rb +8 -0
  98. data/test/ua.yml +26 -3
  99. data/test/ua_bots.yml +9 -2
  100. data/test/ua_search_engines.yml +1 -0
  101. data/test/unit/accept_language_test.rb +6 -0
  102. data/test/unit/adobe_air_test.rb +1 -1
  103. data/test/unit/alipay_test.rb +6 -0
  104. data/test/unit/blackberry_test.rb +0 -6
  105. data/test/unit/bots_test.rb +26 -39
  106. data/test/unit/chrome_test.rb +8 -3
  107. data/test/unit/console_test.rb +2 -2
  108. data/test/unit/device_test.rb +30 -3
  109. data/test/unit/duck_duck_go_test.rb +37 -0
  110. data/test/unit/edge_test.rb +34 -6
  111. data/test/unit/firefox_test.rb +0 -3
  112. data/test/unit/google_search_app_test.rb +54 -0
  113. data/test/unit/huawei_browser_test.rb +25 -0
  114. data/test/unit/internet_explorer_test.rb +0 -12
  115. data/test/unit/ios_test.rb +0 -5
  116. data/test/unit/kai_os_test.rb +31 -0
  117. data/test/unit/kindle_test.rb +0 -2
  118. data/test/unit/maxthon_test.rb +25 -0
  119. data/test/unit/meta_test.rb +10 -2
  120. data/test/unit/micro_messenger_test.rb +21 -6
  121. data/test/unit/miui_browser_test.rb +25 -0
  122. data/test/unit/opera_test.rb +1 -2
  123. data/test/unit/platform_test.rb +13 -8
  124. data/test/unit/qq_test.rb +12 -0
  125. data/test/unit/safari_test.rb +12 -7
  126. data/test/unit/samsung_browser_test.rb +23 -0
  127. data/test/unit/sougou_browser_test.rb +41 -0
  128. data/test/unit/sputnik_test.rb +1 -0
  129. metadata +46 -16
  130. data/.bundle/config +0 -2
  131. data/.travis.yml +0 -23
  132. data/lib/browser/meta/modern.rb +0 -11
  133. /data/gemfiles/{rails6.gemfile → rails6_0.gemfile} +0 -0
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo Switch/i
15
+ ua.match?(/Nintendo Switch/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /(\btv|Android.*?ADT-1|Nexus Player)/i
15
+ ua.match?(/(\btv|Android.*?ADT-1|Nexus Player)/i)
16
16
  end
17
17
  end
18
18
  end
@@ -4,7 +4,7 @@ module Browser
4
4
  class Device
5
5
  class Unknown < Base
6
6
  def id
7
- :unknown
7
+ :unknown_device
8
8
  end
9
9
 
10
10
  def name
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo Wii/i
15
+ ua.match?(/Nintendo Wii/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo WiiU/i
15
+ ua.match?(/Nintendo WiiU/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Xbox/i
15
+ ua.match?(/Xbox/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Xbox One/i
15
+ ua.match?(/Xbox One/i)
16
16
  end
17
17
  end
18
18
  end
@@ -1,25 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "browser/device/base"
4
- require "browser/device/android"
5
- require "browser/device/unknown"
6
- require "browser/device/ipad"
7
- require "browser/device/ipod_touch"
8
- require "browser/device/iphone"
9
- require "browser/device/playstation3"
10
- require "browser/device/playstation4"
11
- require "browser/device/psp"
12
- require "browser/device/psvita"
13
- require "browser/device/kindle"
14
- require "browser/device/kindle_fire"
15
- require "browser/device/wii"
16
- require "browser/device/wiiu"
17
- require "browser/device/blackberry_playbook"
18
- require "browser/device/surface"
19
- require "browser/device/switch"
20
- require "browser/device/tv"
21
- require "browser/device/xbox_one"
22
- require "browser/device/xbox_360"
3
+ require_relative "device/base"
4
+ require_relative "device/android"
5
+ require_relative "device/unknown"
6
+ require_relative "device/ipad"
7
+ require_relative "device/ipod_touch"
8
+ require_relative "device/iphone"
9
+ require_relative "device/playstation3"
10
+ require_relative "device/playstation4"
11
+ require_relative "device/psp"
12
+ require_relative "device/psvita"
13
+ require_relative "device/kindle"
14
+ require_relative "device/kindle_fire"
15
+ require_relative "device/wii"
16
+ require_relative "device/wiiu"
17
+ require_relative "device/blackberry_playbook"
18
+ require_relative "device/surface"
19
+ require_relative "device/switch"
20
+ require_relative "device/tv"
21
+ require_relative "device/xbox_one"
22
+ require_relative "device/xbox_360"
23
+ require_relative "device/samsung"
23
24
 
24
25
  module Browser
25
26
  class Device
@@ -29,6 +30,7 @@ module Browser
29
30
  # Order is important.
30
31
  def self.matchers
31
32
  @matchers ||= [
33
+ Samsung,
32
34
  XboxOne,
33
35
  Xbox360,
34
36
  Surface,
@@ -88,7 +90,7 @@ module Browser
88
90
  end
89
91
 
90
92
  def unknown?
91
- id == :unknown
93
+ id == :unknown_device
92
94
  end
93
95
 
94
96
  def ipod_touch?
@@ -158,12 +160,12 @@ module Browser
158
160
 
159
161
  # Detect if browser is Silk.
160
162
  def silk?
161
- ua =~ /Silk/
163
+ ua.include?("Silk")
162
164
  end
163
165
 
164
166
  # Detect if browser is running under Xbox.
165
167
  def xbox?
166
- ua =~ /Xbox/
168
+ ua.include?("Xbox")
167
169
  end
168
170
 
169
171
  # Detect if browser is running under Xbox 360.
@@ -191,18 +193,26 @@ module Browser
191
193
  xbox? || playstation? || nintendo?
192
194
  end
193
195
 
196
+ # Detect if device is a Samsung.
197
+ def samsung?
198
+ id == :samsung
199
+ end
200
+
194
201
  # Regex taken from http://detectmobilebrowsers.com
195
- # rubocop:disable Metrics/LineLength
202
+ # rubocop:disable Layout/LineLength
196
203
  private def detect_mobile?
197
204
  psp? ||
198
- /zunewp7/i.match(ua) ||
205
+ /zunewp7/i.match?(ua) ||
199
206
  %r{(android|bb\d+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino}i.match(ua) ||
200
- %r{1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-}i.match(ua[0..3])
207
+ %r{1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-}i.match?(ua[0..3])
201
208
  end
202
- # rubocop:enable Metrics/LineLength
209
+ # rubocop:enable Layout/LineLength
203
210
 
204
211
  private def platform
205
212
  @platform ||= Platform.new(ua)
206
213
  end
214
+
215
+ private :subject
216
+ private :ua
207
217
  end
208
218
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class DuckDuckGo < Base
5
+ def id
6
+ :duckduckgo
7
+ end
8
+
9
+ def name
10
+ "DuckDuckGo"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{DuckDuckGo/([\d.]+)}, 1] ||
15
+ "0.0"
16
+ end
17
+
18
+ def match?
19
+ ua.include?("DuckDuckGo")
20
+ end
21
+ end
22
+ end
data/lib/browser/edge.rb CHANGED
@@ -11,15 +11,15 @@ module Browser
11
11
  end
12
12
 
13
13
  def full_version
14
- ua[%r{(?:Edge|Edg)/([\d.]+)}, 1] || super
14
+ ua[%r{(?:Edge|Edg|EdgiOS|EdgA)/([\d.]+)}, 1] || super
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ %r{((?:Edge|Edg)/[\d.]+|Trident/8)}
18
+ ua.match?(%r{((?:Edge|Edg|EdgiOS|EdgA)/[\d.]+|Trident/8)})
19
19
  end
20
20
 
21
21
  def chrome_based?
22
- match? && ua =~ /\bEdg\b/
22
+ match? && ua.match?(/\bEdg\b/)
23
23
  end
24
24
  end
25
25
  end
@@ -16,7 +16,7 @@ module Browser
16
16
  end
17
17
 
18
18
  def match?
19
- ua =~ /Electron/
19
+ ua.include?("Electron")
20
20
  end
21
21
  end
22
22
  end
@@ -17,7 +17,7 @@ module Browser
17
17
  end
18
18
 
19
19
  def match?
20
- ua =~ /FBAV|FBAN/
20
+ ua.match?(/FBAV|FBAN/)
21
21
  end
22
22
  end
23
23
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Firefox|FxiOS/
18
+ ua.match?(/Firefox|FxiOS/)
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class GoogleSearchApp < Chrome
5
+ def id
6
+ :google_search_app
7
+ end
8
+
9
+ def name
10
+ "Google Search App"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{GSA/([\d.]+\d)}, 1] || super
15
+ end
16
+
17
+ def match?
18
+ ua.include?("GSA")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class HuaweiBrowser < Base
5
+ def id
6
+ :huawei_browser
7
+ end
8
+
9
+ def name
10
+ "Huawei Browser"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{(?:HuaweiBrowser)/([\d.]+)}i, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.match?(/HuaweiBrowser/i)
19
+ end
20
+ end
21
+ end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Instagram/
18
+ ua.include?("Instagram")
19
19
  end
20
20
  end
21
21
  end
@@ -52,11 +52,11 @@ module Browser
52
52
  end
53
53
 
54
54
  private def msie?
55
- ua =~ /MSIE/ && ua !~ /Opera/
55
+ ua.include?("MSIE") && !ua.include?("Opera")
56
56
  end
57
57
 
58
58
  private def modern_ie?
59
- ua =~ %r{Trident/.*?; rv:(.*?)}
59
+ ua.match?(%r{Trident/.*?; rv:(.*?)})
60
60
  end
61
61
  end
62
62
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class Maxthon < Base
5
+ def id
6
+ :maxthon
7
+ end
8
+
9
+ def name
10
+ "Maxthon"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{(?:Maxthon)/([\d.]+)}i, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.match?(/Maxthon/i)
19
+ end
20
+ end
21
+ end
@@ -10,7 +10,6 @@ module Browser
10
10
  IE,
11
11
  IOS,
12
12
  Mobile,
13
- Modern,
14
13
  Platform,
15
14
  Proxy,
16
15
  Safari,
data/lib/browser/meta.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "browser/meta/base"
4
- require "browser/meta/generic_browser"
5
- require "browser/meta/id"
6
- require "browser/meta/ie"
7
- require "browser/meta/ios"
8
- require "browser/meta/mobile"
9
- require "browser/meta/modern"
10
- require "browser/meta/platform"
11
- require "browser/meta/proxy"
12
- require "browser/meta/safari"
13
- require "browser/meta/webkit"
14
- require "browser/meta/tablet"
15
- require "browser/meta/device"
3
+ require_relative "meta/base"
4
+ require_relative "meta/generic_browser"
5
+ require_relative "meta/id"
6
+ require_relative "meta/ie"
7
+ require_relative "meta/ios"
8
+ require_relative "meta/mobile"
9
+ require_relative "meta/platform"
10
+ require_relative "meta/proxy"
11
+ require_relative "meta/safari"
12
+ require_relative "meta/webkit"
13
+ require_relative "meta/tablet"
14
+ require_relative "meta/device"
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /MicroMessenger/i
18
+ ua.match?(/MicroMessenger/i)
19
19
  end
20
20
  end
21
21
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "browser/middleware/context/url_methods"
3
+ require_relative "url_methods"
4
4
 
5
5
  module Browser
6
6
  class Middleware
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "uri"
4
- require "browser/middleware/context"
4
+ require_relative "middleware/context"
5
5
 
6
6
  module Browser
7
7
  class Middleware
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class MiuiBrowser < Base
5
+ def id
6
+ :miui_browser
7
+ end
8
+
9
+ def name
10
+ "Miui Browser"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{MiuiBrowser/([\d.]+)}, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.include?("MiuiBrowser")
19
+ end
20
+ end
21
+ end
data/lib/browser/nokia.rb CHANGED
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /S40OviBrowser/
18
+ ua.include?("S40OviBrowser")
19
19
  end
20
20
  end
21
21
  end
data/lib/browser/opera.rb CHANGED
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ %r{(Opera|OPR/)}
18
+ ua.match?(%r{(Opera|OPR/)})
19
19
  end
20
20
  end
21
21
  end
data/lib/browser/otter.rb CHANGED
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Otter/
18
+ ua.include?("Otter")
19
19
  end
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /PhantomJS/
18
+ ua.include?("PhantomJS")
19
19
  end
20
20
  end
21
21
  end
@@ -4,7 +4,7 @@ module Browser
4
4
  class Platform
5
5
  class AdobeAir < Base
6
6
  def match?
7
- ua =~ /AdobeAIR/
7
+ ua.include?("AdobeAIR")
8
8
  end
9
9
 
10
10
  def version
@@ -4,7 +4,7 @@ module Browser
4
4
  class Platform
5
5
  class Android < Base
6
6
  def match?
7
- ua =~ /Android/
7
+ ua.include?("Android") && !ua.include?("KAIOS")
8
8
  end
9
9
 
10
10
  def name
@@ -3,10 +3,11 @@
3
3
  module Browser
4
4
  class Platform
5
5
  class Base
6
- attr_reader :ua
6
+ attr_reader :ua, :platform
7
7
 
8
- def initialize(ua)
8
+ def initialize(ua, platform = nil)
9
9
  @ua = ua
10
+ @platform = platform
10
11
  end
11
12
 
12
13
  def match?
@@ -4,7 +4,7 @@ module Browser
4
4
  class Platform
5
5
  class BlackBerry < Base
6
6
  def match?
7
- ua =~ /BB10|BlackBerry/
7
+ ua.match?(/BB10|BlackBerry/)
8
8
  end
9
9
 
10
10
  def name
@@ -4,7 +4,7 @@ module Browser
4
4
  class Platform
5
5
  class ChromeOS < Base
6
6
  def match?
7
- ua =~ /CrOS/
7
+ ua.include?("CrOS")
8
8
  end
9
9
 
10
10
  def name
@@ -16,7 +16,7 @@ module Browser
16
16
  end
17
17
 
18
18
  def match?
19
- ua !~ /(Android|Linux|BlackBerry|Windows|Mac)/ && ua =~ /Firefox/
19
+ ua !~ /(Android|Linux|BlackBerry|Windows|Mac)/ && ua.include?("Firefox")
20
20
  end
21
21
  end
22
22
  end
@@ -5,7 +5,7 @@ module Browser
5
5
  class IOS < Base
6
6
  MATCHER = /(iPhone|iPad|iPod)/.freeze
7
7
  VERSION_MATCHER =
8
- /OS ((?<major>\d+)_(?<minor>\d+)_?(?<patch>\d+)?)/.freeze
8
+ /OS (?<major>\d+)_(?<minor>\d+)_?(?<patch>\d+)?/.freeze
9
9
 
10
10
  def version
11
11
  matches = VERSION_MATCHER.match(ua)
@@ -32,7 +32,7 @@ module Browser
32
32
  end
33
33
 
34
34
  def match?
35
- ua =~ MATCHER
35
+ ua.match?(MATCHER)
36
36
  end
37
37
 
38
38
  def device
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class Platform
5
+ class KaiOS < Base
6
+ def version
7
+ ua[%r{KAIOS/([\d.]+)}, 1]
8
+ end
9
+
10
+ def name
11
+ "KaiOS"
12
+ end
13
+
14
+ def id
15
+ :kai_os
16
+ end
17
+
18
+ def match?
19
+ ua.include?("KAIOS")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -16,7 +16,7 @@ module Browser
16
16
  end
17
17
 
18
18
  def match?
19
- ua =~ /Linux/
19
+ ua.include?("Linux")
20
20
  end
21
21
  end
22
22
  end
@@ -4,11 +4,13 @@ module Browser
4
4
  class Platform
5
5
  class Mac < Base
6
6
  def version
7
- (ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").tr("_", ".")
7
+ (ua[/Mac OS X\s*([0-9_.]+)?/, 1] || "0").tr("_", ".")
8
8
  end
9
9
 
10
10
  def name
11
- "Macintosh"
11
+ return "macOS" if platform.mac?(">= 10.12")
12
+
13
+ "Mac OS X"
12
14
  end
13
15
 
14
16
  def id
@@ -16,7 +18,7 @@ module Browser
16
18
  end
17
19
 
18
20
  def match?
19
- ua =~ /Mac/
21
+ ua.include?("Mac")
20
22
  end
21
23
  end
22
24
  end
@@ -2,17 +2,17 @@
2
2
 
3
3
  module Browser
4
4
  class Platform
5
- class Other < Base
5
+ class Unknown < Base
6
6
  def version
7
7
  "0"
8
8
  end
9
9
 
10
10
  def name
11
- "Other"
11
+ "Unknown"
12
12
  end
13
13
 
14
14
  def id
15
- :other
15
+ :unknown_platform
16
16
  end
17
17
 
18
18
  def match?