Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
HTTP User Agent parser
Failed to load latest commit information.
lib Always return a NullVersion
spec Always return a NullVersion
.gitignore Add Gemfile
.travis.yml Fast builds
Gemfile Update gemfile source
LICENSE Update copyright year
README.rdoc Update copyright year
Rakefile Upgrade to Rspec 2
useragent.gemspec UserAgent 0.11.0

README.rdoc

UserAgent

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 © 2013 Joshua Peek, released under the MIT license

Something went wrong with that request. Please try again.