Skip to content
HTTP User Agent parser
Branch: master
Clone or download
gshutler Merge pull request #53 from noraj/patch-1
readme: Copyright update
Latest commit 1de7cbf Apr 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Merge pull request #44 from flanker/master Feb 12, 2018
spec Merge pull request #44 from flanker/master Feb 12, 2018
.gitignore Add Gemfile Jul 25, 2011
.travis.yml Test against ruby 2.6 Apr 18, 2019
Gemfile Update gemfile source Mar 23, 2013
LICENSE README to markdown and include my details Mar 14, 2015
README.md readme: Copyright update Feb 7, 2019
Rakefile Make specs run before a release Mar 14, 2015
useragent.gemspec Bumped version to 0.16.10 Feb 12, 2018

README.md

UserAgent

Build Status Gem Version

UserAgent is a Ruby library that parses and compares HTTP User Agents.

Installation

gem install useragent

Examples

Reporting

string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
user_agent = UserAgent.parse(string)
user_agent.browser
# => 'Chrome'
user_agent.version
# => '19.0.1084.56'
user_agent.platform
# => 'Macintosh'

Comparison

Browser = Struct.new(:browser, :version)

SupportedBrowsers = [
  Browser.new("Safari", "3.1.1"),
  Browser.new("Firefox", "2.0.0.14"),
  Browser.new("Internet Explorer", "7.0")
]

user_agent = UserAgent.parse(request.user_agent)
SupportedBrowsers.detect { |browser| user_agent >= browser }

Copyright (c) 2015-2019 Garry Shutler, released under the MIT license

You can’t perform that action at this time.