Module: DetectUserAgent
- Defined in:
- lib/detect_user_agent.rb,
lib/detect_user_agent/os.rb,
lib/detect_user_agent/browser.rb,
lib/detect_user_agent/version.rb,
lib/detect_user_agent/platform.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .browser(useragent) ⇒ Object
- .os(useragent) ⇒ Object
- .parse(useragent) ⇒ Object
- .platform(useragent) ⇒ Object
Class Method Details
.browser(useragent) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/detect_user_agent/browser.rb', line 2 def self.browser(useragent) { /\(BB10;.+Mobile Safari|BlackBerry.+Vendor/ => 'BlackBerry', /MSIE/i => "Internet Explorer", /Chrome/i => "Chrome", /Dolfin/i => "Dolfin", /Jasmine/i => "Jasmine", /NetFront|Playstation|PSP|Nintendo 3DS/i => "NetFront", /Silk/ => "Amazon Silk", /Safari|AppleWebKit/i => "Safari", /Opera|maemo/i => "Opera", /Firefox|gecko/i => "Firefox", /Obigo|Teleca/i => "Obigo", /Nokia\d+/ => "Opera" }.each do |regex,val| return val if useragent=~regex end return "Other" end |
.os(useragent) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/detect_user_agent/os.rb', line 2 def self.os(useragent) { /Android|Nuvifone/i => "Android", /iPad|iPhone|Mobile\/.+Safari/i => "iOS", /Windows (NT|98|XP|Vista|7)|Win98|EA download manager/i => "Windows", /Windows CE|PPC|SAMSUNG-(SGH|GT)|Phone /i => "Windows Mobile", /X11/i => "Linux", /Macintosh/i => "Mac", /playstation/i => "Playstation", /Nintendo/i => "Nintendo", /Symbian|SymbOs|SoftBank/i => "Symbian", /BlackBerry|RIM|\(BB10;/i => "BlackBerry", /PalmSource/i => "Palm", /SAMSUNG.+(Dolfin|Jasmine)|Bada/i => "BadaOs", /ARCHOS/i => "ArchOs", /Linux/i => "Linux", /HTC|WCE/i => "Windows Mobile", /webOS/i => "webOS", /LG-/ => "LG", /Nokia/i => "Nokia", /SonyEricsson/ => "Sony Ericsson" }.each do |regex,val| return val if useragent=~regex end return "Other" end |
.parse(useragent) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/detect_user_agent.rb', line 7 def self.parse(useragent) { platform: platform(useragent), browser: browser(useragent), os: os(useragent) } end |
.platform(useragent) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/detect_user_agent/platform.rb', line 2 def self.platform(useragent) { /iPad/i => "iPad", /iPhone|mobile\/.+Safari/i => "iPhone", /Tablet|Ventana|Froyo|Eclair/i => "Tablet", /Windows (NT|95|98|XP|Vista|7)|Win98|X11|Macintosh|Linux x|EA download manager/i => "Laptop", /Windows CE|Windows Mobile|Windows Phone OS|webOS|WCE|Palm|maemo|Windows.*PPC|Android|Archos|Nuvifone|Folio|obigo/i => "PDA", /playstation|PSP|Nintendo/i => "Console", /\(BB10;|Nokia|SonyEricsson|Symbian|Motorola|Symbos|SoftBank|BlackBerry|SAMSUNG|HTC|LG|Configuration\/CLDC/i => "Phone" }.each do |regex,val| return val if useragent=~regex end return "Other" end |