Class: DeviceWizard::UserAgentDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/device_wizard.rb

Constant Summary collapse

MOBILE =

CONST Keywords

'mobile'
IPAD =
'ipad'
IPHONE =
'iphone'
ANDROID =
'android'
TABLET =
'tablet'
SILK =
'silk'
REGEX_OS =

CONST Regex Patterns

/(windows|linux|os\s+[x9]|solaris|bsd)/
REGEX_MOBILE =
/(iphone|ipod|blackberry|android|palm|windows\s+ce|mobile|symbian|phone)/
REGEX_CRAWLER =
/(spider|crawl|slurp|bot)/

Instance Method Summary collapse

Instance Method Details

#get_device_type(user_agent) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/device_wizard.rb', line 33

def get_device_type(user_agent)

  if user_agent.to_s.strip.length == 0
    return DeviceType::UNKNOWN
  end

  user_agent.downcase!

  if user_agent.include? TABLET
    return DeviceType::TABLET
  end

  if user_agent.include? MOBILE
    if user_agent.include? IPAD
      return DeviceType::TABLET
    else
      return DeviceType::MOBILE
    end
  elsif user_agent.include? ANDROID
    return DeviceType::TABLET
  end

  if REGEX_MOBILE =~ user_agent
    return DeviceType::MOBILE
  end

  if user_agent.include? SILK
    return DeviceType::TABLET
  end

  if REGEX_OS =~ user_agent
    return DeviceType::DESKTOP
  end

  if REGEX_CRAWLER =~ user_agent
    return DeviceType::CRAWLER
  end

  return DeviceType::UNKNOWN

end