2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-09 10:21:41 -04:00
|
|
|
module BrowserDetection
|
|
|
|
|
|
|
|
def self.browser(user_agent)
|
|
|
|
case user_agent
|
2019-07-29 16:51:08 -04:00
|
|
|
when /Edg/i
|
2018-10-22 08:15:41 -04:00
|
|
|
:edge
|
2018-10-09 10:21:41 -04:00
|
|
|
when /Opera/i, /OPR/i
|
|
|
|
:opera
|
|
|
|
when /Firefox/i
|
|
|
|
:firefox
|
|
|
|
when /Chrome/i, /CriOS/i
|
|
|
|
:chrome
|
|
|
|
when /Safari/i
|
|
|
|
:safari
|
|
|
|
when /MSIE/i, /Trident/i
|
|
|
|
:ie
|
2019-08-09 04:56:48 -04:00
|
|
|
when /Discourse/i
|
2019-04-16 13:50:47 -04:00
|
|
|
:discoursehub
|
2018-10-09 10:21:41 -04:00
|
|
|
else
|
|
|
|
:unknown
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.device(user_agent)
|
|
|
|
case user_agent
|
|
|
|
when /Android/i
|
|
|
|
:android
|
2019-05-30 09:29:43 -04:00
|
|
|
when /CrOS/i
|
|
|
|
:chromebook
|
2018-10-09 10:21:41 -04:00
|
|
|
when /iPad/i
|
|
|
|
:ipad
|
|
|
|
when /iPhone/i
|
|
|
|
:iphone
|
|
|
|
when /iPod/i
|
|
|
|
:ipod
|
|
|
|
when /Mobile/i
|
|
|
|
:mobile
|
|
|
|
when /Macintosh/i
|
|
|
|
:mac
|
|
|
|
when /Linux/i
|
|
|
|
:linux
|
|
|
|
when /Windows/i
|
|
|
|
:windows
|
|
|
|
else
|
|
|
|
:unknown
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.os(user_agent)
|
|
|
|
case user_agent
|
|
|
|
when /Android/i
|
|
|
|
:android
|
2019-05-30 09:29:43 -04:00
|
|
|
when /CrOS/i
|
|
|
|
:chromeos
|
2019-08-09 04:56:48 -04:00
|
|
|
when /iPhone|iPad|iPod|Darwin/i
|
2018-10-09 10:21:41 -04:00
|
|
|
:ios
|
|
|
|
when /Macintosh/i
|
|
|
|
:macos
|
|
|
|
when /Linux/i
|
|
|
|
:linux
|
|
|
|
when /Windows/i
|
|
|
|
:windows
|
|
|
|
else
|
|
|
|
:unknown
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|