Class: Browser::Platform

Inherits:
Object
  • Object
show all
Includes:
DetectVersion
Defined in:
lib/browser/platform.rb,
lib/browser/platform/ios.rb,
lib/browser/platform/mac.rb,
lib/browser/platform/base.rb,
lib/browser/platform/linux.rb,
lib/browser/platform/kai_os.rb,
lib/browser/platform/android.rb,
lib/browser/platform/unknown.rb,
lib/browser/platform/windows.rb,
lib/browser/platform/adobe_air.rb,
lib/browser/platform/chrome_os.rb,
lib/browser/platform/blackberry.rb,
lib/browser/platform/firefox_os.rb,
lib/browser/platform/windows_phone.rb,
lib/browser/platform/windows_mobile.rb

Defined Under Namespace

Classes: AdobeAir, Android, Base, BlackBerry, ChromeOS, FirefoxOS, IOS, KaiOS, Linux, Mac, Unknown, Windows, WindowsMobile, WindowsPhone

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ua) ⇒ Platform

Returns a new instance of Platform.



44
45
46
# File 'lib/browser/platform.rb', line 44

def initialize(ua)
  @ua = ua
end

Class Method Details

.matchersObject

Hold the list of platform matchers. Order is important.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/browser/platform.rb', line 26

def self.matchers
  @matchers ||= [
    AdobeAir,
    ChromeOS,
    WindowsMobile,
    WindowsPhone,
    Android,
    BlackBerry,
    IOS,
    Mac,
    KaiOS,
    FirefoxOS,
    Windows,
    Linux,
    Unknown
  ]
end

Instance Method Details

#==(other) ⇒ Object



122
123
124
# File 'lib/browser/platform.rb', line 122

def ==(other)
  id == other
end

#adobe_air?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/browser/platform.rb', line 54

def adobe_air?(expected_version = nil)
  id == :adobe_air && detect_version?(version, expected_version)
end

#android?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/browser/platform.rb', line 62

def android?(expected_version = nil)
  id == :android && detect_version?(version, expected_version)
end

#android_app?Boolean Also known as: android_webview?

Detect if in an Android app webview (Lollipop and newer) developer.chrome.com/multidevice/user-agent#webview_user_agent

Returns:

  • (Boolean)


138
139
140
# File 'lib/browser/platform.rb', line 138

def android_app?
  android? && ua.match?(/\bwv\b/)
end

#blackberry?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/browser/platform.rb', line 94

def blackberry?(expected_version = nil)
  id == :blackberry && detect_version?(version, expected_version)
end

#chrome_os?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/browser/platform.rb', line 58

def chrome_os?(expected_version = nil)
  id == :chrome_os && detect_version?(version, expected_version)
end

#firefox_os?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/browser/platform.rb', line 82

def firefox_os?
  id == :firefox_os
end

#idObject



106
107
108
# File 'lib/browser/platform.rb', line 106

def id
  subject.id
end

#ios?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/browser/platform.rb', line 90

def ios?(expected_version = nil)
  id == :ios && detect_version?(version, expected_version)
end

#ios_app?Boolean

Detect if running on iOS app webview.

Returns:

  • (Boolean)


127
128
129
# File 'lib/browser/platform.rb', line 127

def ios_app?
  ios? && !ua.include?("Safari")
end

#ios_webview?Boolean

Detect if is iOS webview.

Returns:

  • (Boolean)


132
133
134
# File 'lib/browser/platform.rb', line 132

def ios_webview?
  ios_app?
end

#kai_os?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/browser/platform.rb', line 86

def kai_os?
  id == :kai_os
end

#linux?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/browser/platform.rb', line 70

def linux?
  id == :linux
end

#mac?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/browser/platform.rb', line 74

def mac?(expected_version = nil)
  id == :mac && detect_version?(version, expected_version)
end

#nameObject



114
115
116
# File 'lib/browser/platform.rb', line 114

def name
  subject.name
end

#to_sObject



118
119
120
# File 'lib/browser/platform.rb', line 118

def to_s
  id.to_s
end

#unknown?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/browser/platform.rb', line 66

def unknown?
  id == :unknown_platform
end

#versionObject



110
111
112
# File 'lib/browser/platform.rb', line 110

def version
  subject.version
end

#windows10?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/browser/platform.rb', line 164

def windows10?
  windows? && ua.include?("Windows NT 10")
end

#windows7?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/browser/platform.rb', line 152

def windows7?
  windows? && ua.include?("Windows NT 6.1")
end

#windows8?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/browser/platform.rb', line 156

def windows8?
  windows? && ua.match?(/Windows NT 6\.[2-3]/)
end

#windows8_1?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/browser/platform.rb', line 160

def windows8_1?
  windows? && ua.include?("Windows NT 6.3")
end

#windows?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/browser/platform.rb', line 78

def windows?(expected_version = nil)
  id == :windows && detect_version?(version, expected_version)
end

#windows_mobile?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/browser/platform.rb', line 102

def windows_mobile?(expected_version = nil)
  id == :windows_mobile && detect_version?(version, expected_version)
end

#windows_phone?(expected_version = nil) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/browser/platform.rb', line 98

def windows_phone?(expected_version = nil)
  id == :windows_phone && detect_version?(version, expected_version)
end

#windows_rt?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/browser/platform.rb', line 168

def windows_rt?
  windows8? && ua.include?("ARM")
end

#windows_touchscreen_desktop?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/browser/platform.rb', line 185

def windows_touchscreen_desktop?
  windows? && ua.include?("Touch")
end

#windows_vista?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/browser/platform.rb', line 148

def windows_vista?
  windows? && ua.include?("Windows NT 6.0")
end

#windows_wow64?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/browser/platform.rb', line 177

def windows_wow64?
  windows? && ua.match?(/WOW64/i)
end

#windows_x64?Boolean

Detect if current platform is Windows in 64-bit architecture.

Returns:

  • (Boolean)


173
174
175
# File 'lib/browser/platform.rb', line 173

def windows_x64?
  windows? && ua.match?(/(Win64|x64|Windows NT 5\.2)/)
end

#windows_x64_inclusive?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/browser/platform.rb', line 181

def windows_x64_inclusive?
  windows_x64? || windows_wow64?
end

#windows_xp?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/browser/platform.rb', line 144

def windows_xp?
  windows? && ua.match?(/Windows NT 5\.[12]/)
end