module Browser

Constants

EMPTY_STRING
Error
VERSION

Attributes

accept_language_size_limit[RW]
user_agent_size_limit[RW]

Public Class Methods

[](key) click to toggle source
# File lib/browser/testing.rb, line 24
def self.[](key)
  user_agents.fetch(key)
end
bot_user_agents() click to toggle source
# File lib/browser/testing.rb, line 14
def self.bot_user_agents
  @bot_user_agents ||= YAML.load_file(Browser.root.join("test/ua_bots.yml"))
end
browser_user_agents() click to toggle source
# File lib/browser/testing.rb, line 10
def self.browser_user_agents
  @browser_user_agents ||= YAML.load_file(Browser.root.join("test/ua.yml"))
end
matchers() click to toggle source

Hold the list of browser matchers. Order is important.

# File lib/browser/browser.rb, line 69
def self.matchers
  @matchers ||= [
    Nokia,
    UCBrowser,
    PhantomJS,
    BlackBerry,
    Opera,
    Edge,
    InternetExplorer,
    Firefox,
    Otter,
    Facebook,             # must be placed before Chrome and Safari
    Instagram,            # must be placed before Chrome and Safari
    Snapchat,             # must be placed before Chrome and Safari
    Weibo,                # must be placed before Chrome and Safari
    MicroMessenger,       # must be placed before QQ
    QQ,                   # must be placed before Chrome and Safari
    Alipay,               # must be placed before Chrome and Safari
    Electron,             # must be placed before Chrome and Safari
    Yandex,               # must be placed before Chrome and Safari
    Sputnik,              # must be placed before Chrome and Safari
    DuckDuckGo,           # must be placed before Chrome and Safari
    SamsungBrowser,       # must be placed before Chrome and Safari
    HuaweiBrowser,        # must be placed before Chrome and Safari
    MiuiBrowser,          # must be placed before Chrome and Safari
    Maxthon,              # must be placed before Chrome and Safari
    SougouBrowser,        # must be placed before Chrome and Safari
    GoogleSearchApp,      # must be placed before Chrome and Safari
    Chrome,
    Safari,
    Unknown
  ]
end
new(user_agent, **kwargs) click to toggle source
# File lib/browser/browser.rb, line 103
def self.new(user_agent, **kwargs)
  matchers.each do |matcher_class|
    matcher = matcher_class.new(user_agent || EMPTY_STRING, **kwargs)
    return matcher if matcher.match?
  end
end
root() click to toggle source
# File lib/browser/browser.rb, line 56
def self.root
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
end
search_engine_user_agents() click to toggle source
# File lib/browser/testing.rb, line 18
def self.search_engine_user_agents
  @search_engine_user_agents ||= YAML.load_file(
    Browser.root.join("test/ua_search_engines.yml")
  )
end
user_agents() click to toggle source
# File lib/browser/testing.rb, line 4
def self.user_agents
  @user_agents ||= browser_user_agents
                   .merge(bot_user_agents)
                   .merge(search_engine_user_agents)
end