browser 1.1.0 → 2.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.hound.yml +26 -6
- data/.rubocop.yml +26 -6
- data/CHANGELOG.md +10 -0
- data/README.md +177 -41
- data/Rakefile +1 -1
- data/bin/rake +16 -0
- data/bot_exceptions.yml +1 -0
- data/bots.yml +188 -192
- data/browser.gemspec +14 -28
- data/languages.yml +54 -54
- data/lib/browser.rb +82 -202
- data/lib/browser/accept_language.rb +47 -0
- data/lib/browser/action_controller.rb +1 -1
- data/lib/browser/base.rb +159 -0
- data/lib/browser/blackberry.rb +21 -0
- data/lib/browser/bot.rb +63 -0
- data/lib/browser/chrome.rb +23 -0
- data/lib/browser/detect_version.rb +19 -0
- data/lib/browser/device.rb +175 -0
- data/lib/browser/device/base.rb +11 -0
- data/lib/browser/device/blackberry_playbook.rb +17 -0
- data/lib/browser/device/ipad.rb +17 -0
- data/lib/browser/device/iphone.rb +17 -0
- data/lib/browser/device/ipod_touch.rb +17 -0
- data/lib/browser/device/kindle.rb +17 -0
- data/lib/browser/device/kindle_fire.rb +17 -0
- data/lib/browser/device/playstation3.rb +17 -0
- data/lib/browser/device/playstation4.rb +17 -0
- data/lib/browser/device/psp.rb +17 -0
- data/lib/browser/device/psvita.rb +17 -0
- data/lib/browser/device/surface.rb +23 -0
- data/lib/browser/device/tv.rb +17 -0
- data/lib/browser/device/unknown.rb +17 -0
- data/lib/browser/device/wii.rb +17 -0
- data/lib/browser/device/wiiu.rb +17 -0
- data/lib/browser/device/xbox_360.rb +17 -0
- data/lib/browser/device/xbox_one.rb +17 -0
- data/lib/browser/edge.rb +19 -0
- data/lib/browser/firefox.rb +19 -0
- data/lib/browser/generic.rb +32 -0
- data/lib/browser/internet_explorer.rb +61 -0
- data/lib/browser/meta/base.rb +1 -1
- data/lib/browser/meta/device.rb +9 -0
- data/lib/browser/meta/generic_browser.rb +1 -1
- data/lib/browser/meta/id.rb +1 -1
- data/lib/browser/meta/ie.rb +1 -1
- data/lib/browser/meta/ios.rb +2 -2
- data/lib/browser/meta/mobile.rb +2 -2
- data/lib/browser/meta/modern.rb +1 -1
- data/lib/browser/meta/platform.rb +2 -2
- data/lib/browser/meta/proxy.rb +1 -1
- data/lib/browser/meta/safari.rb +1 -1
- data/lib/browser/meta/tablet.rb +9 -0
- data/lib/browser/meta/webkit.rb +1 -1
- data/lib/browser/middleware.rb +1 -1
- data/lib/browser/middleware/context.rb +2 -2
- data/lib/browser/middleware/context/additions.rb +1 -1
- data/lib/browser/middleware/context/url_methods.rb +3 -3
- data/lib/browser/nokia.rb +19 -0
- data/lib/browser/opera.rb +19 -0
- data/lib/browser/phantom_js.rb +19 -0
- data/lib/browser/platform.rb +152 -0
- data/lib/browser/platform/adobe_air.rb +21 -0
- data/lib/browser/platform/android.rb +21 -0
- data/lib/browser/platform/base.rb +15 -0
- data/lib/browser/platform/blackberry.rb +21 -0
- data/lib/browser/platform/chrome_os.rb +21 -0
- data/lib/browser/platform/firefox_os.rb +21 -0
- data/lib/browser/platform/ios.rb +28 -0
- data/lib/browser/platform/linux.rb +21 -0
- data/lib/browser/platform/mac.rb +21 -0
- data/lib/browser/platform/other.rb +21 -0
- data/lib/browser/platform/windows.rb +21 -0
- data/lib/browser/platform/windows_mobile.rb +21 -0
- data/lib/browser/platform/windows_phone.rb +21 -0
- data/lib/browser/rails.rb +3 -2
- data/lib/browser/safari.rb +22 -0
- data/lib/browser/testing.rb +23 -0
- data/lib/browser/uc_browser.rb +19 -0
- data/lib/browser/version.rb +2 -7
- data/search_engines.yml +5 -5
- data/test/browser_test.rb +71 -172
- data/test/middleware_test.rb +7 -7
- data/test/sample_app.rb +3 -3
- data/test/test_helper.rb +11 -10
- data/test/ua.yml +15 -26
- data/test/ua_bots.yml +27 -0
- data/test/ua_search_engines.yml +6 -0
- data/test/unit/accept_language_test.rb +92 -0
- data/test/unit/adobe_air_test.rb +5 -10
- data/test/unit/android_test.rb +44 -49
- data/test/unit/blackberry_test.rb +55 -77
- data/test/unit/bots_test.rb +52 -84
- data/test/unit/chrome_test.rb +48 -42
- data/test/unit/console_test.rb +4 -62
- data/test/unit/device_test.rb +193 -0
- data/test/unit/firefox_test.rb +32 -27
- data/test/unit/ie_test.rb +223 -238
- data/test/unit/ios_app_test.rb +3 -3
- data/test/unit/ios_test.rb +87 -94
- data/test/unit/kindle_test.rb +10 -24
- data/test/unit/nokia_test.rb +3 -7
- data/test/unit/opera_test.rb +20 -30
- data/test/unit/platform_test.rb +161 -0
- data/test/unit/proxy_test.rb +3 -3
- data/test/unit/safari_test.rb +66 -0
- data/test/unit/uc_browser_test.rb +3 -7
- data/test/unit/windows_phone_test.rb +19 -40
- data/test/unit/windows_test.rb +32 -34
- metadata +73 -28
- data/lib/browser/methods/blackberry.rb +0 -51
- data/lib/browser/methods/bots.rb +0 -35
- data/lib/browser/methods/consoles.rb +0 -43
- data/lib/browser/methods/devices.rb +0 -41
- data/lib/browser/methods/ie.rb +0 -99
- data/lib/browser/methods/language.rb +0 -16
- data/lib/browser/methods/mobile.rb +0 -35
- data/lib/browser/methods/platform.rb +0 -152
- data/lib/browser/methods/proxy.rb +0 -8
- data/lib/browser/methods/tv.rb +0 -8
@@ -1,51 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module BlackBerry
|
3
|
-
# Return BlackBerry version.
|
4
|
-
def blackberry_version
|
5
|
-
ua[/BB(10)/, 1] ||
|
6
|
-
ua[/BlackBerry\d+\/(\d+)/, 1] ||
|
7
|
-
ua[/BlackBerry.*?Version\/(\d+)/, 1]
|
8
|
-
end
|
9
|
-
|
10
|
-
# Detect if browser is BlackBerry
|
11
|
-
def blackberry?(version = nil)
|
12
|
-
!!(ua =~ /(BlackBerry|BB10)/) && detect_version?(blackberry_version, version)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Detect if is BlackBerry 4.
|
16
|
-
def blackberry4?
|
17
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
18
|
-
blackberry?(4)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Detect if is BlackBerry 5.
|
22
|
-
def blackberry5?
|
23
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
24
|
-
blackberry?(5)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Detect if is BlackBerry 6.
|
28
|
-
def blackberry6?
|
29
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
30
|
-
blackberry?(6)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Detect if is BlackBerry 7.
|
34
|
-
def blackberry7?
|
35
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
36
|
-
blackberry?(7)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Detect if is BlackBerry 10.
|
40
|
-
def blackberry10?
|
41
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#blackberry?(version) instead"
|
42
|
-
blackberry?(10)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def blackberry_running_safari?
|
48
|
-
blackberry? && safari?
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/browser/methods/bots.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Bots
|
3
|
-
root = Pathname.new(File.expand_path("../../../..", __FILE__))
|
4
|
-
BOTS = YAML.load_file(root.join("bots.yml"))
|
5
|
-
SEARCH_ENGINES = YAML.load_file(root.join("search_engines.yml"))
|
6
|
-
|
7
|
-
def self.detect_empty_ua!
|
8
|
-
@detect_empty_ua = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.detect_empty_ua?
|
12
|
-
!!@detect_empty_ua
|
13
|
-
end
|
14
|
-
|
15
|
-
def bot?
|
16
|
-
bot_with_empty_ua? || BOTS.any? {|key, _| ua.include?(key) }
|
17
|
-
end
|
18
|
-
|
19
|
-
def bot_name
|
20
|
-
return unless bot?
|
21
|
-
return "Generic Bot" if bot_with_empty_ua?
|
22
|
-
BOTS.find {|key, _| ua.include?(key) }.first
|
23
|
-
end
|
24
|
-
|
25
|
-
def search_engine?
|
26
|
-
SEARCH_ENGINES.any? {|key, _| ua.include?(key) }
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def bot_with_empty_ua?
|
32
|
-
Browser::Bots.detect_empty_ua? && ua.strip == ""
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Consoles
|
3
|
-
# Detect if browser is running under Xbox.
|
4
|
-
def xbox?
|
5
|
-
!!(ua =~ /xbox/i)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Detect if browser is running under Xbox One.
|
9
|
-
def xbox_one?
|
10
|
-
!!(ua =~ /xbox one/i)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Detect if browser is running under PlayStation.
|
14
|
-
def playstation?
|
15
|
-
!!(ua =~ /playstation/i)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Detect if browser is running under PlayStation 4.
|
19
|
-
def playstation4?
|
20
|
-
!!(ua =~ /playstation 4/i)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Detect if browser is Nintendo.
|
24
|
-
def nintendo?
|
25
|
-
!!(ua =~ /nintendo/i)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Detect if browser is console (currently Xbox, PlayStation, or Nintendo).
|
29
|
-
def console?
|
30
|
-
xbox? || playstation? || nintendo?
|
31
|
-
end
|
32
|
-
|
33
|
-
# Detect if browser is running from PSP.
|
34
|
-
def psp?
|
35
|
-
!!(ua =~ /(PSP)/ || psp_vita?)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Detect if browser is running from PSP Vita.
|
39
|
-
def psp_vita?
|
40
|
-
!!(ua =~ /Playstation Vita/)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Devices
|
3
|
-
# Detect if browser is iPhone.
|
4
|
-
def iphone?
|
5
|
-
!!(ua =~ /iPhone/)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Detect if browser is iPad.
|
9
|
-
def ipad?
|
10
|
-
!!(ua =~ /iPad/)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Detect if browser is iPod.
|
14
|
-
def ipod?
|
15
|
-
!!(ua =~ /iPod/)
|
16
|
-
end
|
17
|
-
|
18
|
-
def surface?
|
19
|
-
windows_rt? && !!(ua =~ /Touch/)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Detect if browser is tablet (currently iPad, Android, Surface or Playbook).
|
23
|
-
def tablet?
|
24
|
-
!!(ipad? || (android? && !detect_mobile?) || surface? || playbook?)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Detect if browser is Kindle.
|
28
|
-
def kindle?
|
29
|
-
!!(ua =~ /Kindle/ || silk?)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Detect if browser if a Blackberry Playbook tablet
|
33
|
-
def playbook?
|
34
|
-
!!(ua =~ /PlayBook/ && ua =~ /RIM Tablet/)
|
35
|
-
end
|
36
|
-
|
37
|
-
def windows_touchscreen_desktop?
|
38
|
-
windows? && !!(ua =~ /Touch/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/browser/methods/ie.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module IE
|
3
|
-
TRIDENT_VERSION_REGEX = %r[Trident/([0-9.]+)]
|
4
|
-
MODERN_IE = %r[Trident/.*?; rv:(.*?)]
|
5
|
-
MSIE = %r{MSIE ([\d.]+)|Trident/.*?; rv:([\d.]+)}
|
6
|
-
EDGE = %r{(Edge/[\d.]+|Trident/8)}
|
7
|
-
|
8
|
-
# https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
|
9
|
-
TRIDENT_MAPPING = {
|
10
|
-
"4.0" => "8",
|
11
|
-
"5.0" => "9",
|
12
|
-
"6.0" => "10",
|
13
|
-
"7.0" => "11",
|
14
|
-
"8.0" => "12"
|
15
|
-
}
|
16
|
-
|
17
|
-
def ie_version
|
18
|
-
TRIDENT_MAPPING[trident_version] || msie_version
|
19
|
-
end
|
20
|
-
|
21
|
-
def ie_full_version
|
22
|
-
"#{ie_version}.0"
|
23
|
-
end
|
24
|
-
|
25
|
-
def msie_full_version
|
26
|
-
(ua.match(MSIE) && ($1 || $2)) || "0.0"
|
27
|
-
end
|
28
|
-
|
29
|
-
def msie_version
|
30
|
-
msie_full_version.to_s.split(".").first || "0"
|
31
|
-
end
|
32
|
-
|
33
|
-
# Return the trident version.
|
34
|
-
def trident_version
|
35
|
-
ua.match(TRIDENT_VERSION_REGEX) && $1
|
36
|
-
end
|
37
|
-
|
38
|
-
# Detect if browser is Internet Explorer.
|
39
|
-
def ie?(version = nil)
|
40
|
-
(msie? || modern_ie?) && detect_version?(ie_version, version)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Detect if browser is Internet Explorer 6.
|
44
|
-
def ie6?
|
45
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
46
|
-
ie?(6)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Detect if browser is Internet Explorer 7.
|
50
|
-
def ie7?
|
51
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
52
|
-
ie?(7)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Detect if browser is Internet Explorer 8.
|
56
|
-
def ie8?
|
57
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
58
|
-
ie?(8)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Detect if browser is Internet Explorer 9.
|
62
|
-
def ie9?
|
63
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
64
|
-
ie?(9)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Detect if browser is Internet Explorer 10.
|
68
|
-
def ie10?
|
69
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
70
|
-
ie?(10)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Detect if browser is Internet Explorer 11.
|
74
|
-
def ie11?
|
75
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ie?(version) instead"
|
76
|
-
ie?(11)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Detect if browser is Microsoft Edge.
|
80
|
-
def edge?
|
81
|
-
!!(ua =~ EDGE)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Detect if IE is running in compatibility mode.
|
85
|
-
def compatibility_view?
|
86
|
-
ie? && trident_version && msie_version.to_i < (trident_version.to_i + 4)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def msie?
|
92
|
-
!!(ua =~ /MSIE/ && ua !~ /Opera/)
|
93
|
-
end
|
94
|
-
|
95
|
-
def modern_ie?
|
96
|
-
!!(ua =~ MODERN_IE)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Language
|
3
|
-
LANGUAGES = YAML.load_file(File.expand_path("../../../../languages.yml", __FILE__))
|
4
|
-
|
5
|
-
# Set browser's preferred language
|
6
|
-
attr_writer :accept_language
|
7
|
-
|
8
|
-
# Return an array with all preferred languages that this browser accepts.
|
9
|
-
def accept_language
|
10
|
-
@accept_language
|
11
|
-
.gsub(/;q=[\d.]+/, "")
|
12
|
-
.split(",")
|
13
|
-
.map {|l| l.downcase.gsub(/\s/m, "") }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Mobile
|
3
|
-
# Detect if browser is mobile.
|
4
|
-
def mobile?
|
5
|
-
detect_mobile? && !tablet?
|
6
|
-
end
|
7
|
-
|
8
|
-
# Detect if browser is Opera Mini.
|
9
|
-
def opera_mini?
|
10
|
-
!!(ua =~ /Opera Mini/)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Detect if browser is Adobe AIR.
|
14
|
-
def adobe_air?
|
15
|
-
!!(ua =~ /adobeair/i)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Detect if browser is Nokia S40 Ovi Browser.
|
19
|
-
def nokia?
|
20
|
-
!!(ua =~ /S40OviBrowser/)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# Regex taken from http://detectmobilebrowsers.com
|
26
|
-
def detect_mobile?
|
27
|
-
!!(
|
28
|
-
psp? ||
|
29
|
-
/zunewp7/i.match(ua) ||
|
30
|
-
/(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) ||
|
31
|
-
/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])
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
class Browser
|
2
|
-
module Platform
|
3
|
-
# Detect if browser is Android.
|
4
|
-
def android?(version = nil)
|
5
|
-
!!(ua =~ /Android/ && !opera?) && detect_version?(android_version, version)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Detect Android version.
|
9
|
-
def android_version
|
10
|
-
ua[/Android ([\d.]+)/, 1]
|
11
|
-
end
|
12
|
-
|
13
|
-
# Return the iOS version.
|
14
|
-
def ios_version
|
15
|
-
ua[/OS (\d)/, 1]
|
16
|
-
end
|
17
|
-
|
18
|
-
# Detect if running on iOS app webview.
|
19
|
-
def ios_app?
|
20
|
-
ios? && !ua.include?("Safari")
|
21
|
-
end
|
22
|
-
|
23
|
-
# Detect if is iOS webview.
|
24
|
-
def ios_webview?
|
25
|
-
ios_app?
|
26
|
-
end
|
27
|
-
|
28
|
-
# Detect if browser is ios?.
|
29
|
-
def ios?(version = nil)
|
30
|
-
(ipod? || ipad? || iphone?) && detect_version?(ios_version, version)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Detect if is iOS4.
|
34
|
-
def ios4?
|
35
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
36
|
-
ios?(4)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Detect if is iOS5.
|
40
|
-
def ios5?
|
41
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
42
|
-
ios?(5)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Detect if is iOS6.
|
46
|
-
def ios6?
|
47
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
48
|
-
ios?(6)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Detect if is iOS7.
|
52
|
-
def ios7?
|
53
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
54
|
-
ios?(7)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Detect if is iOS8.
|
58
|
-
def ios8?
|
59
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
60
|
-
ios?(8)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Detect if is iOS9.
|
64
|
-
def ios9?
|
65
|
-
deprecate "Browser##{__method__} is deprecated; use Browser#ios?(version) instead"
|
66
|
-
ios?(9)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Detect if current platform is Macintosh.
|
70
|
-
def mac?
|
71
|
-
!!(ua =~ /Mac OS X/ && !ios?)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Detect if current platform is Windows.
|
75
|
-
def windows?
|
76
|
-
!!(ua =~ /Windows/)
|
77
|
-
end
|
78
|
-
|
79
|
-
## More info here => http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
|
80
|
-
def windows_xp?
|
81
|
-
windows? && !!(ua =~ /Windows NT 5.1/)
|
82
|
-
end
|
83
|
-
|
84
|
-
def windows_vista?
|
85
|
-
windows? && !!(ua =~ /Windows NT 6.0/)
|
86
|
-
end
|
87
|
-
|
88
|
-
def windows7?
|
89
|
-
windows? && !!(ua =~ /Windows NT 6.1/)
|
90
|
-
end
|
91
|
-
|
92
|
-
def windows8?
|
93
|
-
windows? && !!(ua =~ /Windows NT 6.[2-3]/)
|
94
|
-
end
|
95
|
-
|
96
|
-
def windows8_1?
|
97
|
-
windows? && !!(ua =~ /Windows NT 6\.3/)
|
98
|
-
end
|
99
|
-
|
100
|
-
def windows10?
|
101
|
-
windows? && !!(ua =~ /Windows NT 10/)
|
102
|
-
end
|
103
|
-
|
104
|
-
def windows_rt?
|
105
|
-
windows8? && !!(ua =~ /ARM/)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Detect if current platform is Windows Mobile.
|
109
|
-
def windows_mobile?
|
110
|
-
!!(ua =~ /Windows CE/)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Detect if current platform is Windows Phone.
|
114
|
-
def windows_phone?
|
115
|
-
!!(ua =~ /Windows Phone/)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Detect if current platform is Windows in 64-bit architecture.
|
119
|
-
def windows_x64?
|
120
|
-
!!(windows? && ua =~ /(Win64|x64)/)
|
121
|
-
end
|
122
|
-
|
123
|
-
def windows_wow64?
|
124
|
-
windows? && !!(ua =~ /WOW64/i)
|
125
|
-
end
|
126
|
-
|
127
|
-
def windows_x64_inclusive?
|
128
|
-
windows_x64? || windows_wow64?
|
129
|
-
end
|
130
|
-
|
131
|
-
# Detect if current platform is Linux flavor.
|
132
|
-
def linux?
|
133
|
-
!!(ua =~ /Linux/)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Detect if current platform is ChromeOS
|
137
|
-
def chrome_os?
|
138
|
-
!!(ua =~ /CrOS/)
|
139
|
-
end
|
140
|
-
|
141
|
-
# Return the platform.
|
142
|
-
def platform
|
143
|
-
case
|
144
|
-
when linux? then :linux
|
145
|
-
when mac? then :mac
|
146
|
-
when windows? then :windows
|
147
|
-
else
|
148
|
-
:other
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|