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_version

Class Method Details

.challenge_firefox(ua, result) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/woothee/browser.rb', line 55

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
# 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?

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

.challenge_opera(ua, result) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/woothee/browser.rb', line 68

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/woothee/browser.rb', line 24

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

  version = Woothee::VALUE_UNKNOWN

  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

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

.challenge_sleipnir(ua, result) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/woothee/browser.rb', line 83

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