A crystal shard for parsing user agent strings using the BrowserScope pattern library.
Add this to your application's shard.yml
:
dependencies:
user_agent_parser:
github: busyloop/user_agent_parser
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=[])>)
- Fork it (https://github.com/busyloop/user_agent_parser/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request