Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (53 sloc) 2.154 kb

UserAgentParser Build Status

UserAgentParser is a simple, comprehensive Ruby gem for parsing user agent strings. It uses BrowserScope's parsing patterns.

Requirements

  • Ruby >= 1.9.2

Note: Ruby 1.8.7 is not supported due to the requirement for the newer psych YAML parser. If you can get it working on 1.8.7 please send a pull request.

Installation

$ gem install user_agent_parser

Example usage

require 'user_agent_parser'
=> true
ua = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)'
=> #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)>
ua.to_s
=> "IE 9.0"
ua.family
=> "IE"
ua.version.to_s
=> "9.0"
ua.version.major
=> 9
ua.version.minor
=> 0
os = ua.os
=> #<UserAgentParser::OperatingSystem Windows Vista>
os.to_s
=> "Windows Vista"

The pattern database

The ua-parser database is included via a git submodule. To update the database the submodule needs to be updated and the gem re-released (pull requests for this are very welcome!).

You can also specify the path to your own, updated and/or customised regexes.yaml file:

UserAgentParser.patterns_path = '/some/path/to/regexes.yaml'

Comprehensive you say?

$ rake test
...

Finished tests in 144.220280s, 89.0027 tests/s, 234.9739 assertions/s.

12836 tests, 33888 assertions, 0 failures, 0 errors, 0 skips

Limitations

There's no support for providing overrides from Javascript user agent detection like there is with original BrowserScope library. The Javascript overrides were only necessary for detecting IE 9 Platform Preview and older versions of Chrome Frame.

Contributing

  1. Fork
  2. Hack
  3. rake test
  4. Send a pull request

All accepted pull requests will earn you commit and release rights.

License

MIT

Jump to Line
Something went wrong with that request. Please try again.