Sha256: fd3f7cc1e785d788015713e79ba2ae36f1f5743c62dce1eacfc577f28b33424f

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

class UserAgent
  module Browsers
    class Chrome < Base
      def self.extend?(agent)
        agent.detect { |useragent|
          useragent.product == 'Chrome' ||
            useragent.product == 'CriOS'
        }
      end

      def browser
        'Chrome'
      end

      def build
        webkit.version
      end

      # Prior to Safari 3, the user agent did not include a version number
      def version
        str = if detect_product("CriOs")
          crios.version
        else
          chrome.version
        end

        Version.new(str)
      end

      def application
        self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first
      end

      def platform
        if application.nil?
          nil
        elsif application.comment[0] =~ /Windows/
          'Windows'
        else
          application.comment[0]
        end
      end

      def webkit
        detect { |useragent| useragent.product == "AppleWebKit" }
      end

      def os
        if application
          if application.comment[0] =~ /Windows NT/
            OperatingSystems.normalize_os(application.comment[0])
          elsif application.comment[2].nil?
            OperatingSystems.normalize_os(application.comment[1])
          elsif application.comment[1] =~ /Android/
            OperatingSystems.normalize_os(application.comment[1])
          else
            OperatingSystems.normalize_os(application.comment[2])
          end
        else
          nil
        end
      end

      def localization
        if application.nil?
          nil
        else
          application.comment[3]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
useragent-0.13.3 lib/user_agent/browsers/chrome.rb
useragent-0.13.2 lib/user_agent/browsers/chrome.rb
useragent-0.13.1 lib/user_agent/browsers/chrome.rb
useragent-0.13.0 lib/user_agent/browsers/chrome.rb
useragent-0.12.0 lib/user_agent/browsers/chrome.rb
useragent-0.11.0 lib/user_agent/browsers/chrome.rb