Module: Browser

Defined in:
lib/browser/qq.rb,
lib/browser/bot.rb,
lib/browser/base.rb,
lib/browser/edge.rb,
lib/browser/nokia.rb,
lib/browser/opera.rb,
lib/browser/otter.rb,
lib/browser/rails.rb,
lib/browser/weibo.rb,
lib/browser/alipay.rb,
lib/browser/chrome.rb,
lib/browser/device.rb,
lib/browser/safari.rb,
lib/browser/yandex.rb,
lib/browser/aliases.rb,
lib/browser/browser.rb,
lib/browser/firefox.rb,
lib/browser/generic.rb,
lib/browser/meta/id.rb,
lib/browser/meta/ie.rb,
lib/browser/sputnik.rb,
lib/browser/testing.rb,
lib/browser/version.rb,
lib/browser/electron.rb,
lib/browser/facebook.rb,
lib/browser/meta/ios.rb,
lib/browser/platform.rb,
lib/browser/snapchat.rb,
lib/browser/device/tv.rb,
lib/browser/instagram.rb,
lib/browser/meta/base.rb,
lib/browser/blackberry.rb,
lib/browser/device/psp.rb,
lib/browser/device/wii.rb,
lib/browser/meta/proxy.rb,
lib/browser/middleware.rb,
lib/browser/phantom_js.rb,
lib/browser/uc_browser.rb,
lib/browser/device/base.rb,
lib/browser/device/ipad.rb,
lib/browser/device/wiiu.rb,
lib/browser/meta/device.rb,
lib/browser/meta/mobile.rb,
lib/browser/meta/safari.rb,
lib/browser/meta/tablet.rb,
lib/browser/meta/webkit.rb,
lib/browser/duck_duck_go.rb,
lib/browser/platform/ios.rb,
lib/browser/platform/mac.rb,
lib/browser/device/iphone.rb,
lib/browser/device/kindle.rb,
lib/browser/device/psvita.rb,
lib/browser/device/switch.rb,
lib/browser/meta/platform.rb,
lib/browser/platform/base.rb,
lib/browser/detect_version.rb,
lib/browser/device/android.rb,
lib/browser/device/surface.rb,
lib/browser/device/unknown.rb,
lib/browser/platform/linux.rb,
lib/browser/platform/other.rb,
lib/browser/accept_language.rb,
lib/browser/device/xbox_360.rb,
lib/browser/device/xbox_one.rb,
lib/browser/micro_messenger.rb,
lib/browser/platform/android.rb,
lib/browser/platform/windows.rb,
lib/browser/action_controller.rb,
lib/browser/device/ipod_touch.rb,
lib/browser/internet_explorer.rb,
lib/browser/device/kindle_fire.rb,
lib/browser/middleware/context.rb,
lib/browser/platform/adobe_air.rb,
lib/browser/platform/chrome_os.rb,
lib/browser/bot/keyword_matcher.rb,
lib/browser/device/playstation3.rb,
lib/browser/device/playstation4.rb,
lib/browser/platform/blackberry.rb,
lib/browser/platform/firefox_os.rb,
lib/browser/meta/generic_browser.rb,
lib/browser/bot/known_bots_matcher.rb,
lib/browser/platform/windows_phone.rb,
lib/browser/platform/windows_mobile.rb,
lib/browser/device/blackberry_playbook.rb,
lib/browser/bot/empty_user_agent_matcher.rb,
lib/browser/middleware/context/additions.rb,
lib/browser/middleware/context/url_methods.rb

Defined Under Namespace

Modules: ActionController, Aliases, DetectVersion, Meta Classes: AcceptLanguage, Alipay, Base, BlackBerry, Bot, Chrome, Device, DuckDuckGo, Edge, Electron, Facebook, Firefox, Generic, Instagram, InternetExplorer, MicroMessenger, Middleware, Nokia, Opera, Otter, PhantomJS, Platform, QQ, Railtie, Safari, Snapchat, Sputnik, UCBrowser, Weibo, Yandex

Constant Summary collapse

EMPTY_STRING =
""
VERSION =
"4.0.0"

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



24
25
26
# File 'lib/browser/testing.rb', line 24

def self.[](key)
  user_agents.fetch(key)
end

.bot_user_agentsObject



14
15
16
# 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_agentsObject



10
11
12
# 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

.matchersObject

Hold the list of browser matchers. Order is important.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/browser/browser.rb', line 54

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
    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
    Chrome,
    Safari,
    MicroMessenger,
    Generic
  ]
end

.new(user_agent, **kwargs) ⇒ Object



82
83
84
85
86
# File 'lib/browser/browser.rb', line 82

def self.new(user_agent, **kwargs)
  matchers
    .map {|klass| klass.new(user_agent || EMPTY_STRING, **kwargs) }
    .find(&:match?)
end

.rootObject



48
49
50
# File 'lib/browser/browser.rb', line 48

def self.root
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
end

.search_engine_user_agentsObject



18
19
20
21
22
# File 'lib/browser/testing.rb', line 18

def self.search_engine_user_agents
  @search_engine_user_agents ||= begin
    YAML.load_file(Browser.root.join("test/ua_search_engines.yml"))
  end
end

.user_agentsObject



4
5
6
7
8
# 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