Module: Woothee::Browser

Extended by:
Util
Defined in:
lib/woothee/browser.rb

Class Method Summary collapse

Methods included from Util

update_category, update_map, update_os, update_os_version, update_version

Class Method Details

.challenge_firefox(ua, result) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/woothee/browser.rb', line 94

def self.challenge_firefox(ua, result)
  return false if ua.index('Firefox/').nil?

  version = if ua =~ /Firefox\/([.0-9]+)/o
              $1
            else
              Woothee::VALUE_UNKNOWN
            end
  update_map(result, Woothee::DataSet.get('Firefox'))
  update_version(result, version)
  true
end

.challenge_msie(ua, result) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/woothee/browser.rb', line 9

def self.challenge_msie(ua, result)
  return false if ua.index("compatible; MSIE").nil? && ua.index("Trident/").nil? && ua.index("IEMobile").nil?

  version = if ua =~ /MSIE ([.0-9]+);/o
              $1
            elsif ua =~ /Trident\/([.0-9]+);/o && ua =~ / rv:([.0-9]+)/
              $1
            elsif ua =~ /IEMobile\/([.0-9]+);/o
              $1
            else
              Woothee::VALUE_UNKNOWN
            end
  update_map(result, Woothee::DataSet.get('MSIE'))
  update_version(result, version)
  true
end

.challenge_opera(ua, result) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/woothee/browser.rb', line 107

def self.challenge_opera(ua, result)
  return false if ua.index('Opera').nil?

  version = if ua =~ /Version\/([.0-9]+)/o
              $1
            elsif ua =~ /Opera[\/ ]([.0-9]+)/o
              $1
            else
              Woothee::VALUE_UNKNOWN
            end
  update_map(result, Woothee::DataSet.get('Opera'))
  update_version(result, version)
  true
end

.challenge_safari_chrome(ua, result) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/woothee/browser.rb', line 39

def self.challenge_safari_chrome(ua, result)
  return false if ua.index('Safari/').nil?
  return false if ua.index('Chrome') && ua.index('wv')

  version = Woothee::VALUE_UNKNOWN

  # Edge
  if ua =~ /(?:Edge|Edg|EdgiOS|EdgA)\/([.0-9]+)/o
    version = $1
    update_map(result, Woothee::DataSet.get('Edge'))
    update_version(result, version)
    return true
  end

  if ua =~ /FxiOS\/([.0-9]+)/o
    version = $1
    update_map(result, Woothee::DataSet.get('Firefox'))
    update_version(result, version)
    return true
  end

  if ua =~ /(?:Chrome|CrMo|CriOS)\/([.0-9]+)/o
    chrome_version = $1

    if ua =~ /OPR\/([.0-9]+)/o
      version = $1
      update_map(result, Woothee::DataSet.get('Opera'))
      update_version(result, version)
      return true
    end

    # Chrome
    version = chrome_version
    update_map(result, Woothee::DataSet.get('Chrome'))
    update_version(result, version)
    return true
  end

  # Google Search App
  if ua =~ /GSA\/([.0-9]+)/o
    version = $1
    update_map(result, Woothee::DataSet.get("GSA"))
    update_version(result, version)
    return true
  end

  # Safari
  if ua =~ /Version\/([.0-9]+)/o
    version = $1
  end
  update_map(result, Woothee::DataSet.get('Safari'))
  update_version(result, version)
  true
end

.challenge_samsungbrowser(ua, result) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/woothee/browser.rb', line 185

def self.challenge_samsungbrowser(ua, result)
  return false if ua.index('SamsungBrowser/').nil?

  version = Woothee::VALUE_UNKNOWN
  if ua =~ /SamsungBrowser\/([.0-9]+)/o
    version = $1
  end

  update_map(result, Woothee::DataSet.get('SamsungBrowser'))
  update_version(result, version)
  true
end

.challenge_sleipnir(ua, result) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/woothee/browser.rb', line 153

def self.challenge_sleipnir(ua, result)
  return false if ua.index('Sleipnir/').nil?

  version = if ua =~ /Sleipnir\/([.0-9]+)/o
              $1
            else
              Woothee::VALUE_UNKNOWN
            end
  update_map(result, Woothee::DataSet.get('Sleipnir'))
  update_version(result, version)

  # Sleipnir's user-agent doesn't contain Windows version, so put 'Windows UNKNOWN Ver'.
  # Sleipnir is IE component browser, so for Windows only.
  win = Woothee::DataSet.get('Win')
  update_category(result, win[Woothee::KEY_CATEGORY])
  update_os(result, win[Woothee::KEY_NAME])

  true
end

.challenge_vivaldi(ua, result) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/woothee/browser.rb', line 173

def self.challenge_vivaldi(ua, result)
  return false if ua.index('Vivaldi/').nil?

  version = if ua =~ /Vivaldi\/([.0-9]+)/o
              $1
            else
              Woothee::VALUE_UNKNOWN
            end
  update_map(result, Woothee::DataSet.get('Vivaldi'))
  update_version(result, version)
end

.challenge_webview(ua, result) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/woothee/browser.rb', line 122

def self.challenge_webview(ua, result)
  # Android(Lollipop and Above)
  if ua.index('Chrome') && ua.index('wv')
    version = if ua =~ /Version\/([.0-9]+)/
                $1
              else
                Woothee::VALUE_UNKNOWN
              end

    update_map(result, Woothee::DataSet.get('Webview'))
    update_version(result, version)
    return true
  end

  # iOS
  if ua =~ /iP(?:hone;|ad;|od) .*like Mac OS X/
    return false if ua.index('Safari/')

    version = if ua =~ /Version\/([.0-9]+)/
                $1
              else
                Woothee::VALUE_UNKNOWN
              end
    update_map(result, Woothee::DataSet.get('Webview'))
    update_version(result, version)
    return true
  end

  false
end

.challenge_yandexbrowser(ua, result) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/woothee/browser.rb', line 26

def self.challenge_yandexbrowser(ua, result)
  return false if ua.index('YaBrowser/').nil?

  version = Woothee::VALUE_UNKNOWN
  if ua =~ /YaBrowser\/([.0-9]+)/o
    version = $1
  end

  update_map(result, Woothee::DataSet.get('YaBrowser'))
  update_version(result, version)
  true
end