Sha256: 3a8596cdc4bbba0ef8e70ea3bbac48ca124a3cba93465a2bc4060f68f752f104

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

module BrowserslistUseragent
  # Normalizes browserslist query to existing browser family names
  class QueryNormalizer
    NORMALIZED_NAMES = {
      bb: 'BlackBerry',
      and_chr: 'Chrome',
      ChromeAndroid: 'Chrome',
      FirefoxAndroid: 'Firefox',
      ff: 'Firefox',
      ie: 'Explorer',
      ie_mob: 'ExplorerMobile',
      and_ff: 'Firefox',
      ios_saf: 'iOS',
      op_mini: 'OperaMini',
      op_mob: 'OperaMobile',
      and_qq: 'QQAndroid',
      and_uc: 'UCAndroid'
    }.freeze

    attr_reader :query

    def initialize(query)
      @query = query
    end

    def call
      browser_name, browser_version = query.split(' ', 2)
      normalized_name = NORMALIZED_NAMES[browser_name.to_sym] || browser_name

      { family: normalized_name, version: browser_version }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
browserslist_useragent-0.2.0 lib/browserslist_useragent/query_normalizer.rb
browserslist_useragent-0.1.3 lib/browserslist_useragent/query_normalizer.rb
browserslist_useragent-0.1.1 lib/browserslist_useragent/query_normalizer.rb
browserslist_useragent-0.1.0 lib/browserslist_useragent/query_normalizer.rb