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/maxthon.rb,
lib/browser/meta/id.rb,
lib/browser/meta/ie.rb,
lib/browser/sputnik.rb,
lib/browser/testing.rb,
lib/browser/unknown.rb,
lib/browser/version.rb,
lib/browser/electron.rb,
lib/browser/epiphany.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/miui_browser.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/samsung.rb,
lib/browser/device/surface.rb,
lib/browser/device/unknown.rb,
lib/browser/huawei_browser.rb,
lib/browser/platform/linux.rb,
lib/browser/sougou_browser.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/kai_os.rb,
lib/browser/samsung_browser.rb,
lib/browser/platform/android.rb,
lib/browser/platform/unknown.rb,
lib/browser/platform/windows.rb,
lib/browser/action_controller.rb,
lib/browser/device/ipod_touch.rb,
lib/browser/google_search_app.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, Epiphany, Facebook, Firefox, GoogleSearchApp, HuaweiBrowser, Instagram, InternetExplorer, Maxthon, MicroMessenger, Middleware, MiuiBrowser, Nokia, Opera, Otter, PhantomJS, Platform, QQ, Railtie, Safari, SamsungBrowser, Snapchat, SougouBrowser, Sputnik, UCBrowser, Unknown, Weibo, Yandex

Constant Summary collapse

EMPTY_STRING =
""
Error =
Class.new(StandardError)
VERSION =
"6.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.accept_language_size_limitObject

Returns the value of attribute accept_language_size_limit.



62
63
64
# File 'lib/browser/browser.rb', line 62

def accept_language_size_limit
  @accept_language_size_limit
end

.user_agent_size_limitObject

Returns the value of attribute user_agent_size_limit.



62
63
64
# File 'lib/browser/browser.rb', line 62

def user_agent_size_limit
  @user_agent_size_limit
end

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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/browser/browser.rb', line 70

def self.matchers
  @matchers ||= [
    Nokia,
    UCBrowser,
    PhantomJS,
    BlackBerry,
    Opera,
    Edge,
    InternetExplorer,
    Firefox,
    Otter,
    Epiphany,
    Facebook,
    Instagram,
    Snapchat,
    Weibo,
    MicroMessenger, # must be placed before QQ
    QQ,
    Alipay,
    Electron,
    Yandex,
    Sputnik,
    DuckDuckGo,
    SamsungBrowser,
    HuaweiBrowser,
    MiuiBrowser,
    Maxthon,
    SougouBrowser,
    GoogleSearchApp,

    # Must be last
    Chrome,
    Safari,
    Unknown
  ]
end

.new(user_agent, **kwargs) ⇒ Object



107
108
109
110
111
112
# File 'lib/browser/browser.rb', line 107

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

.rootObject



57
58
59
# File 'lib/browser/browser.rb', line 57

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 ||= YAML.load_file(
    Browser.root.join("test/ua_search_engines.yml")
  )
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