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 = headers['Sec-CH-UA-Full-Version']
  @browser_list = extract_browser_list
  @app_name = extract_app_name
  @platform = headers['Sec-CH-UA-Platform']
  @platform_version = extract_platform_version
  @mobile = headers['Sec-CH-UA-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
# File 'lib/device_detector/client_hint.rb', line 29

def browser_name
  return 'Iridium' if is_iridium?

  browser_name_from_list || app_name
end

#os_familyObject



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

def os_family
  return if os_short_name.nil?

  DeviceDetector::OS::FAMILY_TO_OS[os_short_name]
end

#os_nameObject



41
42
43
44
45
46
# File 'lib/device_detector/client_hint.rb', line 41

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

  platform
end

#os_short_nameObject



48
49
50
51
52
# File 'lib/device_detector/client_hint.rb', line 48

def os_short_name
  return if os_name.nil?

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

#os_versionObject



35
36
37
38
39
# File 'lib/device_detector/client_hint.rb', line 35

def os_version
  return windows_version if platform == 'Windows'

  platform_version
end