Class: UserAgent::Browsers::Chrome

Inherits:
Base
  • Object
show all
Defined in:
lib/user_agent/browsers/chrome.rb

Constant Summary collapse

ChromeBrowsers =
%w(
  Iron
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, #bot?, #eql?, #method_missing, #mobile?, #respond_to?, #to_h, #to_s, #to_str

Methods included from Comparable

#<, #<=, #==, #>, #>=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UserAgent::Browsers::Base

Class Method Details

.extend?(agent) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/user_agent/browsers/chrome.rb', line 4

def self.extend?(agent)
  agent.detect { |useragent|
    %w(Chrome CriOS).include?(useragent.product)
  }
end

Instance Method Details

#applicationObject



33
34
35
# File 'lib/user_agent/browsers/chrome.rb', line 33

def application
  self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first
end

#browserObject



14
15
16
# File 'lib/user_agent/browsers/chrome.rb', line 14

def browser
  ChromeBrowsers.detect { |browser| respond_to?(browser) } || 'Chrome'
end

#buildObject



18
19
20
# File 'lib/user_agent/browsers/chrome.rb', line 18

def build
  webkit.version
end

#localizationObject



69
70
71
72
73
# File 'lib/user_agent/browsers/chrome.rb', line 69

def localization
  return unless application

  application.comment[3]
end

#osObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/user_agent/browsers/chrome.rb', line 55

def os
  return unless application

  if application.comment[0] =~ /Windows NT/
    OperatingSystems.normalize_os(application.comment[0])
  elsif application.comment[2].nil?
    OperatingSystems.normalize_os(application.comment[1])
  elsif application.comment[1] =~ /Android/
    OperatingSystems.normalize_os(application.comment[1])
  else
    OperatingSystems.normalize_os(application.comment[2])
  end
end

#platformObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/user_agent/browsers/chrome.rb', line 37

def platform
  return unless application

  if application.comment[0] =~ /Windows/
    'Windows'
  elsif application.comment.any? { |c| c =~ /CrOS/ }
    'ChromeOS'
  elsif application.comment.any? { |c| c =~ /Android/ }
    'Android'
  else
    application.comment[0]
  end
end

#versionObject

Prior to Safari 3, the user agent did not include a version number



23
24
25
26
27
28
29
30
31
# File 'lib/user_agent/browsers/chrome.rb', line 23

def version
  str = if detect_product("CriOs")
    crios.version
  else
    chrome.version
  end

  Version.new(str)
end

#webkitObject



51
52
53
# File 'lib/user_agent/browsers/chrome.rb', line 51

def webkit
  detect { |useragent| useragent.product == "AppleWebKit" }
end