Crystal shard for device detection by User-Agent string
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bench
spec
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
shard.yml

README.md

Device Detector

Build Status

The library for parsing User Agent and browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), vendor and model detection. Currently it is an alpha-version and haven't been tested on production yet. The Library uses regexes from matomo-org/device_detector.

Installation

Add this to your application's shard.yml:

dependencies:
  device_detector:
    github: creadone/device_detector

Usage

require "device_detector"

user_agent = "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0"
response = DeviceDetector::Detector.new(user_agent).call

# Check if browser detected
response.browser? #=> true

# Get browser name
response.browser_name #=> Microsoft Edge

# Get browser version
response.browser_version #=> 12.0

Available methods:

bot?
bot_name
browser_engine?
browser_engine_name
browser?
browser_name
browser_version
camera?
camera_vendor
camera_model
car_browser?
car_browser_vendor
car_browser_model
console?
console_vendor
console_model
feed_reader?
feed_reader_name
feed_reader_version
library?
library_name
library_version
mediaplayer?
mediaplayer_name
mediaplayer_version
mobile_app?
mobile_app_name
mobile_app_version
mobile_device?
mobile_device_vendor
mobile_device_type
mobile_device_model
os?
os_name
os_version
pim?
pim_name
pim_version
portable_media_player?
portable_media_player_vendor
portable_media_player_model
tv?
tv_vendor
tv_model
vendorfragment?
vendorfragment_vendor

Benchmarks

Recent benchmarking of parsing 1000 user-agent strings on a MacBook Air with Intel Core i5 dual core (0.8 Ghz per core):

crystal bench/raw_response.cr --release
40.530000   1.420000   41.950000 (  39.998607)

It's mean that device_detector can work with 25 RPS.

Testing

crystal spec

Contributing

  1. Fork it ( https://github.com/creadone/device_detector/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

Contributors

  • @creadone Sergey Fedorov - creator, maintainer