Readme.md in user_agent_parser-1.0.2 vs Readme.md in user_agent_parser-2.0.0

- old
+ new

@@ -2,14 +2,12 @@ UserAgentParser is a simple, comprehensive Ruby gem for parsing user agent strings. It uses [BrowserScope](http://www.browserscope.org/)'s [parsing patterns](https://github.com/tobie/ua-parser). ## Requirements -* Ruby >= 1.9.2 +* Ruby >= 1.8.7 -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 ```bash $ gem install user_agent_parser ``` @@ -17,53 +15,52 @@ ## Example usage ```ruby require 'user_agent_parser' => true -ua = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)' +user_agent = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)' => #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)> -ua.to_s +user_agent.to_s => "IE 9.0" -ua.family +user_agent.name => "IE" -ua.version.to_s +user_agent.version.to_s => "9.0" -ua.version.major -=> 9 -ua.version.minor -=> 0 -os = ua.os +user_agent.version.major +=> "9" +user_agent.version.minor +=> "0" +operating_system = user_agent.os => #<UserAgentParser::OperatingSystem Windows Vista> -os.to_s +operating_system.to_s => "Windows Vista" + +# The parser database will be loaded and parsed on every call to +# UserAgentParser.parse. To avoid this, instantiate your own Parser instance. +parser = UserAgentParser::Parser.new +parser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)' +=> #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)> +parser.parse 'Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.5.24 Version/10.53' +=> #<UserAgentParser::UserAgent Opera 10.53 (Windows XP)> ``` ## The pattern database The [ua-parser database](https://github.com/tobie/ua-parser/blob/master/regexes.yaml) is included via a [git submodule](http://help.github.com/submodules/). 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: +You can also specify the path to your own, updated and/or customised `regexes.yaml` file as a second argument to `UserAgentParser.parse`: ```ruby -UserAgentParser.patterns_path = '/some/path/to/regexes.yaml' +UserAgentParser.parse(ua_string, patterns_path: '/some/path/to/regexes.yaml') ``` -## Comprehensive you say? +or when instantiating a `UserAgentParser::Parser`: -```bash -$ 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 +```ruby +UserAgentParser::Parser.new(patterns_path: '/some/path/to/regexes.yaml').parse(ua_string) ``` -## 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](https://developers.google.com/chrome/chrome-frame/). - ## Contributing 1. Fork 2. Hack 3. `rake test` @@ -71,6 +68,6 @@ All accepted pull requests will earn you commit and release rights. ## License -MIT \ No newline at end of file +MIT