DeviceDetectorUser-Agent 解析庫
DeviceDetector 是一個用 Ruby 編寫的用來解析各種設備 User-Agent 信息的庫,基于及時更新和龐大的 user-agent 庫。使用 DeviceDetector 可探測設備瀏覽器、操作系統(tǒng)、設備類型(桌面、平板、移動、電視、汽車、控制臺等)、品牌和型號。
示例代碼:
user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36' client = DeviceDetector.new(user_agent) client.name # => 'Chrome' client.full_version # => '30.0.1599.69' client.os_name # => 'Windows' client.os_full_version # => '8' # For many devices, you can also query the device name (usually the model name) client.device_name # => 'iPhone 5' # Device types can be one of the following: smartphone, tablet, console, # portable media player, tv, car browser, camera client.device_type # => 'smartphone'
為了提升性能,DeviceDetector 可以把 UserAgent 信息放到緩存中:
DeviceDetector.configure do |config| config.max_cache_keys = 5_000 # increment this if you have enough RAM, proceed with care end
評論
圖片
表情
