File: internet_explorer.rb

package info (click to toggle)
ruby-useragent 0.16.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 368 kB
  • sloc: ruby: 4,824; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
54
55
56
57
58
59
60
61
62
class UserAgent
  module Browsers
    class InternetExplorer < Base
      TRIDENT_ENGINES = {
        "Trident/8.0" => "11.0",
        "Trident/7.0" => "11.0",
        "Trident/6.0" => "10.0",
        "Trident/5.0" => "9.0",
        "Trident/4.0" => "8.0",
      }.freeze

      def self.extend?(agent)
        agent.application &&
        agent.application.comment &&
        (agent.application.comment[1] =~ /MSIE/ ||
         agent.application.comment.join('; ') =~ /Trident.+rv:/)
      end

      def browser
        "Internet Explorer"
      end

      def version
        str = application.comment.join('; ')[/(MSIE\s|rv:)([\d\.]+)/, 2]
        Version.new(str)
      end

      def trident_version
        if trident = application.comment.detect { |c| c['Trident/'] }
          trident_version = TRIDENT_ENGINES.fetch(trident, trident)
          Version.new(trident_version)
        end
      end

      def real_version
        [trident_version, version].sort.last
      end

      def compatibility_view?
        trident_version && version < real_version
      end

      # Before version 4.0, Chrome Frame declared itself (unversioned) in a comment;
      # as of 4.0 it can declare itself versioned in a comment
      # or as a separate product with a version
      def chromeframe
        cf = application.comment.include?("chromeframe") || detect_product("chromeframe")
        return cf if cf
        cf_comment = application.comment.detect { |c| c['chromeframe/'] }
        cf_comment ? UserAgent.new(*cf_comment.split('/', 2)) : nil
      end

      def platform
        "Windows"
      end

      def os
        OperatingSystems.normalize_os(application.comment.join('; ').match(/Windows NT [\d\.]+|Windows Phone (OS )?[\d\.]+/).to_s)
      end
    end
  end
end