Sha256: ee2ba2c5f775c1a1ec4d90454b6c36efad234ee111a4649097bc144bfb8c61d7

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 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"
    }

    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.]+)}) && ($1 || $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.
    def trident_version
      ua.match(%r[Trident/([0-9.]+)]) && $1
    end

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

    def modern_ie?
      ua =~ %r[Trident/.*?; rv:(.*?)]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
browser-2.2.0 lib/browser/internet_explorer.rb
browser-2.1.0 lib/browser/internet_explorer.rb
browser-2.0.3 lib/browser/internet_explorer.rb
browser-2.0.2 lib/browser/internet_explorer.rb
browser-2.0.1 lib/browser/internet_explorer.rb