module DetectUserAgent

Constants

VERSION

Public Class Methods

browser(useragent) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/detect_user_agent.rb, line 7
def self.parse(useragent)
  {
    platform: platform(useragent),
    browser: browser(useragent),
    os: os(useragent)
  }
end
platform(useragent) click to toggle source
# 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