All Projects → ua-parser → Uap Ruby

ua-parser / Uap Ruby

Licence: mit
A simple, comprehensive Ruby gem for parsing user agent strings with the help of BrowserScope's UA database

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Uap Ruby

Daw json link
Static JSON parsing in C++
Stars: ✭ 146 (-22.34%)
Mutual labels:  parse
Next Useragent
next-useragent parses browser user-agent strings for next.js
Stars: ✭ 158 (-15.96%)
Mutual labels:  useragent
Libpypa
libpypa is a Python parser implemented in pure C++
Stars: ✭ 172 (-8.51%)
Mutual labels:  parse
Parse Sdk Android
The Android SDK for the Parse Platform
Stars: ✭ 1,806 (+860.64%)
Mutual labels:  parse
Html Agility Pack
Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
Stars: ✭ 2,014 (+971.28%)
Mutual labels:  parse
Parser
A lexer and parser for GraphQL in .NET
Stars: ✭ 163 (-13.3%)
Mutual labels:  parse
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-22.87%)
Mutual labels:  parse
Magnet Uri
Parse a magnet URI and return an object of keys/values
Stars: ✭ 183 (-2.66%)
Mutual labels:  parse
Bm25
A Python implementation of the BM25 ranking function.
Stars: ✭ 159 (-15.43%)
Mutual labels:  parse
Cicero
Accord Project Smart Templates Implementation
Stars: ✭ 166 (-11.7%)
Mutual labels:  parse
Slang
SystemVerilog compiler and language services
Stars: ✭ 145 (-22.87%)
Mutual labels:  parse
Bash Parser
Parses bash into an AST
Stars: ✭ 151 (-19.68%)
Mutual labels:  parse
Pegparser
💡 Build your own programming language! A C++17 PEG parser generator supporting parser combination, memoization, left-recursion and context-dependent grammars.
Stars: ✭ 164 (-12.77%)
Mutual labels:  parse
Libnmea
Lightweight C library for parsing NMEA 0183 sentences
Stars: ✭ 146 (-22.34%)
Mutual labels:  parse
Discovery
Discoveries on Sustainable Loading research
Stars: ✭ 174 (-7.45%)
Mutual labels:  parse
Genieparser
sub-component of Genie that parse the device output into structured datastructure
Stars: ✭ 146 (-22.34%)
Mutual labels:  parse
Parseurl
parse a url with memoization
Stars: ✭ 162 (-13.83%)
Mutual labels:  parse
Flags
⛳ Simple, extensible, header-only C++17 argument parser released into the public domain.
Stars: ✭ 187 (-0.53%)
Mutual labels:  parse
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-4.26%)
Mutual labels:  parse
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (-11.17%)
Mutual labels:  parse

UserAgentParser Build Status Coverage Status

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

Supported Rubies

  • Ruby 2.6
  • Ruby 2.5
  • Ruby 2.4
  • JRuby

Installation

$ gem install user_agent_parser

Example usage

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

# Device information can also be determined from some devices
user_agent = UserAgentParser.parse "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G930T Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.0 Chrome/51.0.2704.106 Mobile Safari/537.36"
=> #<UserAgentParser::UserAgent Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)>
user_agent.device.family
=> "Samsung SM-G930T"
user_agent.device.brand
=> "Samsung"
user_agent.device.model
=> "SM-G930T"

user_agent = UserAgentParser.parse "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/23.1.148956103 Mobile/14D27 Safari/600.1.4"
=> #<UserAgentParser::UserAgent Mobile Safari 10.2.1 (iOS 10.2.1) (iPad)>
irb(main):026:0> user_agent.device.family
=> "iPad"
irb(main):027:0> user_agent.device.brand
=> "Apple"
irb(main):028:0> user_agent.device.model
=> "iPad"


# 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)>

In a larger application, you could store a parser in a global to avoid repeat pattern loading:

module MyApplication

  # Instantiate the parser on load as it's quite expensive
  USER_AGENT_PARSER = UserAgentParser::Parser.new

  def self.user_agent_parser
    USER_AGENT_PARSER
  end

end

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 as a second argument to UserAgentParser.parse:

UserAgentParser.parse(ua_string, patterns_path: '/some/path/to/regexes.yaml')

or when instantiating a UserAgentParser::Parser:

UserAgentParser::Parser.new(patterns_path: '/some/path/to/regexes.yaml').parse(ua_string)

Command line tool

The gem incldes a user_agent_parser bin command which will read from standard input, parse each line and print the result, for example:

$ cat > SOME-FILE-WITH-USER-AGENTS.txt
USER_AGENT_1
USER_AGENT_2
...
$ cat SOME-FILE-WITH-USER-AGENTS.txt | user_agent_parser --format '%f %M' | distribution

See user_agent_parser -h for more information.

Contributing

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

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

Releasing a new version

  1. Update the version in user_agent_parser.gemspec

  2. git commit user_agent_parser.gemspec with the following message format:

     Version x.x.x
    
     Changelog:
     * Some new feature
     * Some new bug fix
    
  3. rake release

  4. Create a new Github release

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].