Testing machine specsĬode require ' device_detector ' require ' browser ' require ' user_agent ' require ' benchmark ' user_agent_strings = File. We have measured the parsing speed of almost 200,000 non-unique user agent strings and compared the speed of DeviceDetector with the two most popular user agent parsers in the Ruby community, Browser and UserAgent. If you have a Rails application, you can create an initializer, for example config/initializers/device_detector.rb. max_cache_keys = 5_000 # increment this if you have enough RAM, proceed with care
#Polybrowser code#
You have to call this code before you initialize the Detector. You can tune the amount of keys that will get saved in the cache. known? # => will return false if user_agent is unknownĭeviceDetector will cache up 5,000 user agent strings to boost parsing performance. You can make a check to ensure the client has been detected: client.
#Polybrowser portable#
# portable media player, phablet, smart speaker, wearable, peripheralĭeviceDetector will return nil on all attributes, if the user_agent is unknown. # feature phone, console, tv, car browser, smart display, camera, # Device types can be one of the following: desktop, smartphone, tablet, # For many devices, you can also query the device name (usually the model name) Usage user_agent = ' Mozilla/5.0 (Windows NT 6.2 WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/.17 Safari/537.36 ' client = DeviceDetector.
#Polybrowser install#
Or install it yourself as: $ gem install device_detector InstallationĪdd this line to your application's Gemfile: gem ' device_detector ' Still, our goal is to use the original, unchanged regex yaml files, in order to mutually benefit from updates and pull request to both the original and the ported versions. This port does not aspire to be a one-to-one copy from the original code, but rather an adaptation for the Ruby language. This project originated as a Ruby port of the Universal Device Detection library. The DeviceDetector is optimized for speed of detection, by providing optimized code and in-memory caching. DeviceDetector detects thousands of user agent strings, even from rare and obscure browsers and devices. DeviceDetector is a precise and fast user agent parser and device detector written in Ruby, backed by the largest and most up-to-date user agent database.ĭeviceDetector will parse any user agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.