DeviceDetector是一个用Ruby编写的用来解析各种设备User-Aget信息的库,基于及时更新和庞大的user-aget库。使用DeviceDetector可探测设备浏览器、操作系统、设备类型(桌面、平板、移动、电视、汽车、控制台等)、品牌和型号。
示例代码:
user_aget = 'Mozilla/5.0 (Widows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36'cliet = DeviceDetector.ew(user_aget)cliet.ame # => 'Chrome'cliet.full_versio # => '30.0.1599.69'cliet.os_ame # => 'Widows'cliet.os_full_versio # => '8'# For may devices, you ca also query the device ame (usually the model ame)cliet.device_ame # => 'iPhoe 5'# Device types ca be oe of the followig: smartphoe, tablet, cosole, # portable media player, tv, car browser, cameracliet.device_type # => 'smartphoe'为了提升性能,DeviceDetector可以把UserAget信息放到缓存中:
DeviceDetector.cofigure do |cofig| cofig.max_cache_keys = 5_000 # icremet this if you have eough RAM, proceed with careed
评论