class DeviceDetector
Constants
- VERSION
Attributes
user_agent[R]
Public Class Methods
cache()
click to toggle source
# File lib/device_detector.rb, line 136 def cache @cache ||= MemoryCache.new(config.to_hash) end
config()
click to toggle source
# File lib/device_detector.rb, line 132 def config @config ||= Configuration.new end
configure() { |config| ... }
click to toggle source
# File lib/device_detector.rb, line 140 def configure(&block) @config = Configuration.new yield(config) end
new(user_agent)
click to toggle source
# File lib/device_detector.rb, line 19 def initialize(user_agent) @user_agent = user_agent end
Public Instance Methods
bot?()
click to toggle source
# File lib/device_detector.rb, line 112 def bot? bot.bot? end
bot_name()
click to toggle source
# File lib/device_detector.rb, line 116 def bot_name bot.name end
device_brand()
click to toggle source
# File lib/device_detector.rb, line 43 def device_brand device.brand end
device_name()
click to toggle source
# File lib/device_detector.rb, line 39 def device_name device.name end
device_type()
click to toggle source
# File lib/device_detector.rb, line 47 def device_type t = device.type if t.nil? && android_tablet_fragment? || opera_tablet? t = 'tablet' end if t.nil? && android_mobile_fragment? t = 'smartphone' end # Android up to 3.0 was designed for smartphones only. But as 3.0, # which was tablet only, was published too late, there were a # bunch of tablets running with 2.x With 4.0 the two trees were # merged and it is for smartphones and tablets # # So were are expecting that all devices running Android < 2 are # smartphones Devices running Android 3.X are tablets. Device type # of Android 2.X and 4.X+ are unknown if t.nil? && os.short_name == 'AND' && os.full_version && !os.full_version.empty? if os.full_version < '2' t = 'smartphone' elsif os.full_version >= '3' && os.full_version < '4' t = 'tablet' end end # All detected feature phones running android are more likely a smartphone if t == 'feature phone' && os.family == 'Android' t = 'smartphone' end # According to http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx # Internet Explorer 10 introduces the "Touch" UA string token. If this token is present at the end of the # UA string, the computer has touch capability, and is running Windows 8 (or later). # This UA string will be transmitted on a touch-enabled system running Windows 8 (RT) # # As most touch enabled devices are tablets and only a smaller part are desktops/notebooks we assume that # all Windows 8 touch devices are tablets. if t.nil? && touch_enabled? && (os.short_name == 'WRT' || (os.short_name == 'WIN' && os.full_version && os.full_version >= '8')) t = 'tablet' end if opera_tv_store? t = 'tv' end if t.nil? && ['Kylo', 'Espial TV Browser'].include?(client.name) t = 'tv' end # set device type to desktop for all devices running a desktop os that were # not detected as an other device type if t.nil? && os.desktop? && !puffin_browser? t = 'desktop' end t end
full_version()
click to toggle source
# File lib/device_detector.rb, line 27 def full_version client.full_version end
known?()
click to toggle source
# File lib/device_detector.rb, line 108 def known? client.known? end
name()
click to toggle source
# File lib/device_detector.rb, line 23 def name client.name end
os_full_version()
click to toggle source
# File lib/device_detector.rb, line 35 def os_full_version os.full_version end
os_name()
click to toggle source
# File lib/device_detector.rb, line 31 def os_name os.name end
Private Instance Methods
android_mobile_fragment?()
click to toggle source
# File lib/device_detector.rb, line 169 def android_mobile_fragment? user_agent =~ build_regex('Android(?: \d.\d(?:.\d)?)?; Mobile;') end
android_tablet_fragment?()
click to toggle source
# File lib/device_detector.rb, line 165 def android_tablet_fragment? user_agent =~ build_regex('Android(?: \d.\d(?:.\d)?)?; Tablet;') end
bot()
click to toggle source
# File lib/device_detector.rb, line 149 def bot @bot ||= Bot.new(user_agent) end
build_regex(src)
click to toggle source
# File lib/device_detector.rb, line 190 def build_regex(src) Regexp.new('(?:^|[^A-Z0-9\_\-])(?:' + src + ')', Regexp::IGNORECASE) end
client()
click to toggle source
# File lib/device_detector.rb, line 153 def client @client ||= Client.new(user_agent) end
device()
click to toggle source
# File lib/device_detector.rb, line 157 def device @device ||= Device.new(user_agent) end
opera_tablet?()
click to toggle source
# File lib/device_detector.rb, line 181 def opera_tablet? user_agent =~ build_regex('Opera Tablet') end
opera_tv_store?()
click to toggle source
# File lib/device_detector.rb, line 177 def opera_tv_store? user_agent =~ build_regex('Opera TV Store') end
os()
click to toggle source
# File lib/device_detector.rb, line 161 def os @os ||= OS.new(user_agent) end
puffin_browser?()
click to toggle source
This is a workaround until we support detecting mobile only browsers
# File lib/device_detector.rb, line 186 def puffin_browser? client.name == 'Puffin' end
touch_enabled?()
click to toggle source
# File lib/device_detector.rb, line 173 def touch_enabled? user_agent =~ build_regex('Touch') end