GeezerVison is showing github.com — Initial commit · ua-parser/uap-ruby@47b68e9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/pkg/ |
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +[submodule "vendor/ua-parser"] | | 2 | + path = vendor/ua-parser | | 3 | + url = https://github.com/tobie/ua-parser.git |
Collapse file Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +language: ruby | | 2 | +rvm: | | 3 | + - 1.8.7 | | 4 | + - 1.9.2 | | 5 | + - 1.9.3 | | 6 | + - jruby-18mode | | 7 | + - jruby-19mode | | 8 | + - rbx-18mode | | 9 | + - rbx-19mode | | 10 | + - ruby-head | | 11 | + - jruby-head | | 12 | + - ree |
Collapse file Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +source "https://rubygems.org/" | | 2 | + | | 3 | +gemspec | | 4 | + | | 5 | +group :test do | | 6 | + gem "minitest" | | 7 | + gem "json" | | 8 | +end |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +PATH | | 2 | + remote: . | | 3 | + specs: | | 4 | + ua-parser (0.0.1) | | 5 | + | | 6 | +GEM | | 7 | + remote: https://rubygems.org/ | | 8 | + specs: | | 9 | + minitest (2.12.1) | | 10 | + | | 11 | +PLATFORMS | | 12 | + ruby | | 13 | + | | 14 | +DEPENDENCIES | | 15 | + minitest | | 16 | + ua-parser! |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Copyright (c) 2012 Tim Lucas | | 2 | + | | 3 | +Permission is hereby granted, free of charge, to any person obtaining | | 4 | +a copy of this software and associated documentation files (the | | 5 | +"Software"), to deal in the Software without restriction, including | | 6 | +without limitation the rights to use, copy, modify, merge, publish, | | 7 | +distribute, sublicense, and/or sell copies of the Software, and to | | 8 | +permit persons to whom the Software is furnished to do so, subject to | | 9 | +the following conditions: | | 10 | + | | 11 | +The above copyright notice and this permission notice shall be | | 12 | +included in all copies or substantial portions of the Software. | | 13 | + | | 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | | 15 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | | 16 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | | 17 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | | 18 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | | 19 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | | 20 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +require 'rake/testtask' | | 2 | +require 'bundler' | | 3 | + | | 4 | +task :default => :test | | 5 | + | | 6 | +desc "Run tests" | | 7 | +Rake::TestTask.new do |t| | | 8 | + t.warning = true | | 9 | + t.verbose = true | | 10 | + t.pattern = "spec/*_spec.rb" | | 11 | +end | | 12 | + | | 13 | +Bundler::GemHelper.install_tasks |
Collapse file Copy file name to clipboard +62Lines changed: 62 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# UserAgentParser | | 2 | + | | 3 | +UserAgentParser is a simple, comprehensive Ruby gem for parsing user agent strings based upon [BrowserScope](http://www.browserscope.org/)'s UA parser. The parsing patterns come from the most excellent [ua-parser project](https://github.com/tobie/ua-parser) by [Tobie Langel](https://github.com/tobie/). | | 4 | + | | 5 | +## Installation | | 6 | + | | 7 | + $ gem install user_agent_parser | | 8 | + | | 9 | +## Usage example | | 10 | + | | 11 | + require 'user_agent_parser' | | 12 | + => true | | 13 | + ua = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)' | | 14 | + => #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)> | | 15 | + ua.to_s | | 16 | + => "IE 9.0 (Windows Vista)" | | 17 | + ua.family | | 18 | + => "IE" | | 19 | + ua.version.to_s | | 20 | + => "9.0" | | 21 | + ua.version[0] | | 22 | + => 9 | | 23 | + ua.version[1] | | 24 | + => 0 | | 25 | + ua.os.name | | 26 | + => "Windows Vista" | | 27 | + | | 28 | +## The pattern database | | 29 | + | | 30 | +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!). | | 31 | + | | 32 | +You can also specify the path to your own, updated and/or customised `regexes.yaml` file: | | 33 | + | | 34 | + UserAgentParser.patterns_path = '/some/path/to/regexes.yaml' | | 35 | + | | 36 | +## Comprehensive you say? | | 37 | + | | 38 | + $ rake test | | 39 | + ... | | 40 | + | | 41 | + Finished tests in 144.220280s, 89.0027 tests/s, 234.9739 assertions/s. | | 42 | + | | 43 | + 12836 tests, 33888 assertions, 0 failures, 0 errors, 0 skips | | 44 | + | | 45 | +## Limitations | | 46 | + | | 47 | +Unlike the original Browserscope code there's no support for providing overrides from Javascript user agent detection. There's no current intention of adding support as the Javascript overrides were only necessary for IE 9 Platform Preview and older versions of [Chrome Frame](https://developers.google.com/chrome/chrome-frame/). | | 48 | + | | 49 | +Chrome Frame detection is not yet included, but once [ua-parser issue #14](https://github.com/tobie/ua-parser/issues/14) is resolved this gem will be updated along with it. | | 50 | + | | 51 | +## Contributing | | 52 | + | | 53 | +1. Fork | | 54 | +2. Hack | | 55 | +3. `rake test` | | 56 | +4. Send a pull request | | 57 | + | | 58 | +All accepted pull requests will earn you commit and release rights. | | 59 | + | | 60 | +## License | | 61 | + | | 62 | +MIT |
Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +require 'user_agent_parser/parser' | | 2 | +require 'user_agent_parser/user_agent' | | 3 | +require 'user_agent_parser/version' | | 4 | +require 'user_agent_parser/operating_system' | | 5 | + | | 6 | +module UserAgentParser | | 7 | + | | 8 | + # Path to the ua-parser regexes pattern database | | 9 | + def self.patterns_path | | 10 | + @patterns_path | | 11 | + end | | 12 | + | | 13 | + # Sets the path to the ua-parser regexes pattern database | | 14 | + def self.patterns_path=(path) | | 15 | + @patterns_path = path | | 16 | + end | | 17 | + | | 18 | + self.patterns_path = File.join(File.dirname(__FILE__), "../vendor/ua-parser/regexes.yaml") | | 19 | + | | 20 | + # Parse the given +user_agent_string+, returning a +UserAgent+ | | 21 | + def self.parse user_agent_string | | 22 | + Parser.new.parse user_agent_string | | 23 | + end | | 24 | + | | 25 | +end |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +module UserAgentParser | | 2 | + | | 3 | + class OperatingSystem | | 4 | + | | 5 | + attr_accessor :name, :version | | 6 | + | | 7 | + def initialize(name="Other", version=nil) | | 8 | + self.name = name | | 9 | + self.version = version | | 10 | + end | | 11 | + | | 12 | + def to_s | | 13 | + s = name | | 14 | + s += " #{version}" if version | | 15 | + s | | 16 | + end | | 17 | + | | 18 | + def inspect | | 19 | + "#<#{self.class} #{to_s}>" | | 20 | + end | | 21 | + | | 22 | + def ==(other) | | 23 | + name == other.name && version == other.version | | 24 | + end | | 25 | + | | 26 | + end | | 27 | + | | 28 | +end |
|