Class: UserAgent::Browsers::Chrome

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

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
9
# File 'lib/user_agent/browsers/chrome.rb', line 4

def self.extend?(agent)
  agent.detect { |useragent|
    useragent.product == 'Chrome' ||
      useragent.product == 'CriOS'
  }
end

Instance Method Details

#applicationObject



30
31
32
# File 'lib/user_agent/browsers/chrome.rb', line 30

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

#browserObject



11
12
13
# File 'lib/user_agent/browsers/chrome.rb', line 11

def browser
  'Chrome'
end

#buildObject



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

def build
  webkit.version
end

#localizationObject



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

def localization
  if application.nil?
    nil
  else
    application.comment[3]
  end
end

#osObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/user_agent/browsers/chrome.rb', line 50

def os
  if 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
  else
    nil
  end
end

#platformObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/user_agent/browsers/chrome.rb', line 34

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

#versionObject

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



20
21
22
23
24
25
26
27
28
# File 'lib/user_agent/browsers/chrome.rb', line 20

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

  Version.new(str)
end

#webkitObject



46
47
48
# File 'lib/user_agent/browsers/chrome.rb', line 46

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