https://github.com/busyloop/user_agent_parser
Parse user agent strings using the BrowserScope pattern library.
https://github.com/busyloop/user_agent_parser
Last synced: 11 months ago
JSON representation
Parse user agent strings using the BrowserScope pattern library.
- Host: GitHub
- URL: https://github.com/busyloop/user_agent_parser
- Owner: busyloop
- License: mit
- Created: 2018-11-15T18:41:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-07T22:16:25.000Z (over 4 years ago)
- Last Synced: 2025-06-20T10:13:24.180Z (about 1 year ago)
- Language: Crystal
- Size: 75.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# user_agent_parser
[](https://github.com/busyloop/user_agent_parser/releases)
[]()
A crystal shard for parsing user agent strings using the BrowserScope pattern library.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
user_agent_parser:
github: busyloop/user_agent_parser
```
## Usage
```crystal
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=#)
```
## Contributing
1. Fork it ()
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