Class: DeviceDetector::ClientHint

Inherits:
Object
  • Object
show all
Defined in:
lib/device_detector/client_hint.rb

Defined Under Namespace

Classes: HintBrowser

Constant Summary collapse

ROOT =
File.expand_path('../..', __dir__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ ClientHint

Returns a new instance of ClientHint.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/device_detector/client_hint.rb', line 13

def initialize(headers)
  return if headers.nil?

  @headers = headers
  @full_version = extract_full_version
  @browser_list = extract_browser_list
  @app_name = extract_app_name
  @platform = extract_platform
  @platform_version = extract_platform_version
  @mobile = extract_mobile
  @model = extract_model
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def app_name
  @app_name
end

#browser_listObject (readonly)

Returns the value of attribute browser_list.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def browser_list
  @browser_list
end

#full_versionObject (readonly)

Returns the value of attribute full_version.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def full_version
  @full_version
end

#headersObject (readonly)

Returns the value of attribute headers.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def headers
  @headers
end

#mobileObject (readonly)

Returns the value of attribute mobile.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def mobile
  @mobile
end

#modelObject (readonly)

Returns the value of attribute model.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def model
  @model
end

#platformObject (readonly)

Returns the value of attribute platform.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def platform
  @platform
end

#platform_versionObject (readonly)

Returns the value of attribute platform_version.



26
27
28
# File 'lib/device_detector/client_hint.rb', line 26

def platform_version
  @platform_version
end

Instance Method Details

#browser_nameObject



29
30
31
32
33
34
# File 'lib/device_detector/client_hint.rb', line 29

def browser_name
  return 'Iridium' if iridium?
  return '360 Secure Browser' if secure_browser?

  browser_name_from_list || app_name
end

#os_familyObject



59
60
61
62
63
# File 'lib/device_detector/client_hint.rb', line 59

def os_family
  return if os_short_name.nil?

  DeviceDetector::OS::FAMILY_TO_OS[os_short_name]
end

#os_nameObject



44
45
46
47
48
49
50
51
# File 'lib/device_detector/client_hint.rb', line 44

def os_name
  return 'Android' if android_app?
  return 'Lineage OS' if lineage_os_app?
  return 'Fire OS' if fire_os_app?
  return unless ['Windows', 'Chromium OS'].include?(platform)

  platform
end

#os_short_nameObject



53
54
55
56
57
# File 'lib/device_detector/client_hint.rb', line 53

def os_short_name
  return if os_name.nil?

  DeviceDetector::OS::DOWNCASED_OPERATING_SYSTEMS[os_name.downcase]
end

#os_versionObject



36
37
38
39
40
41
42
# File 'lib/device_detector/client_hint.rb', line 36

def os_version
  return windows_version if platform == 'Windows'
  return lineage_version if lineage_os_app?
  return fire_os_version if fire_os_app?

  platform_version
end