user_agent_parser v2.0.1

Parse user agent strings using the BrowserScope pattern library.

user_agent_parser

GitHub release Docs

A crystal shard for parsing user agent strings using the BrowserScope pattern library.

Installation

Add this to your application's shard.yml:

dependencies:
  user_agent_parser:
    github: busyloop/user_agent_parser

Usage

require "user_agent_parser"

## Load BrowserScope patterns, latest version
## can be found here: https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml

UserAgent.load_regexes(File.read("regexes.yaml"))

# 1. Parse a user agent string
ua = UserAgent.new("Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36")

# 2. Inspect the result
puts ua.family # => Chrome Mobile WebView
puts ua.version # => 60.0.3112

puts ua.device # => UserAgent::Device(@model="SM-G892A", @brand="Samsung", @name="Samsung SM-G892A")

puts ua.os # => UserAgent::Os(@family="Android", @version=#<SemanticVersion:0x10c1c97e0 @major=7, @minor=0, @patch=0, @build=nil, @prerelease=SemanticVersion::Prerelease(@identifiers=[])>)

Contributing

  1. Fork it (https://github.com/busyloop/user_agent_parser/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Repository

user_agent_parser

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 1
  • almost 3 years ago
  • November 15, 2018
License

MIT License

Links
Synced at

Sun, 22 Dec 2024 07:56:32 GMT

Languages