Sha256: 6a86120521778651c6e6c0d88c095d87737ca6992a0a2a02783a29b5d46d7957

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Browser
  class InternetExplorer < Base
    # https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
    TRIDENT_MAPPING = {
      "4.0" => "8",
      "5.0" => "9",
      "6.0" => "10",
      "7.0" => "11",
      "8.0" => "12"
    }.freeze

    def id
      :ie
    end

    def name
      "Internet Explorer"
    end

    def full_version
      "#{ie_version}.0"
    end

    def msie_full_version
      (ua.match(%r{MSIE ([\d.]+)|Trident/.*?; rv:([\d.]+)}) &&
        (Regexp.last_match(1) || Regexp.last_match(2))) ||
        "0.0"
    end

    def msie_version
      msie_full_version.split(".").first
    end

    def match?
      msie? || modern_ie?
    end

    # Detect if IE is running in compatibility mode.
    def compatibility_view?
      trident_version && msie_version.to_i < (trident_version.to_i + 4)
    end

    private def ie_version
      TRIDENT_MAPPING[trident_version] || msie_version
    end

    # Return the trident version.
    private def trident_version
      ua.match(%r{Trident/([0-9.]+)}) && Regexp.last_match(1)
    end

    private def msie?
      ua =~ /MSIE/ && ua !~ /Opera/
    end

    private def modern_ie?
      ua =~ %r{Trident/.*?; rv:(.*?)}
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
browser-5.1.0 lib/browser/internet_explorer.rb
browser-5.0.0 lib/browser/internet_explorer.rb
browser-4.2.0 lib/browser/internet_explorer.rb
browser-4.1.0 lib/browser/internet_explorer.rb
browser-4.0.0 lib/browser/internet_explorer.rb
browser-3.0.3 lib/browser/internet_explorer.rb
browser-3.0.2 lib/browser/internet_explorer.rb
browser-3.0.1 lib/browser/internet_explorer.rb
browser-3.0.0 lib/browser/internet_explorer.rb
browser-2.7.1 lib/browser/internet_explorer.rb