Class: DeviceWizard::UserAgentDetector
- Inherits:
-
Object
- Object
- DeviceWizard::UserAgentDetector
- Defined in:
- lib/device_wizard/user_agent_detector.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
- #get_browser(user_agent) ⇒ Object
- #get_details(user_agent) ⇒ Object
- #get_device_type(user_agent) ⇒ Object
- #get_os(user_agent) ⇒ Object
-
#initialize ⇒ UserAgentDetector
constructor
A new instance of UserAgentDetector.
- #unknown ⇒ Object
Constructor Details
#initialize ⇒ UserAgentDetector
Returns a new instance of UserAgentDetector.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/device_wizard/user_agent_detector.rb', line 23 def initialize @browser_resolvers = [] @browser_resolvers.push(Resolvers::Firefox.new) @browser_resolvers.push(Resolvers::GoogleChrome.new) @browser_resolvers.push(Resolvers::InternetExplorer.new) @browser_resolvers.push(Resolvers::Safari.new) @os_resolvers = [] @os_resolvers.push(Resolvers::Android.new) @os_resolvers.push(Resolvers::IOS.new) @os_resolvers.push(Resolvers::Mac.new) @os_resolvers.push(Resolvers::Windows.new) end |
Instance Method Details
#get_browser(user_agent) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/device_wizard/user_agent_detector.rb', line 56 def get_browser(user_agent) @browser_resolvers.each do |r| browser = r.identify(user_agent) return browser unless browser.nil? end Details::Browser.new end |
#get_details(user_agent) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/device_wizard/user_agent_detector.rb', line 74 def get_details(user_agent) details = Details::Device.new details.type = get_device_type(user_agent) details.browser = get_browser(user_agent) details.os = get_os(user_agent) details end |
#get_device_type(user_agent) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/device_wizard/user_agent_detector.rb', line 41 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 type = determine_type(user_agent) type || DeviceType::UNKNOWN end |
#get_os(user_agent) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/device_wizard/user_agent_detector.rb', line 65 def get_os(user_agent) @os_resolvers.each do |r| os = r.identify(user_agent) return os unless os.nil? end Details::OperatingSystem.new end |
#unknown ⇒ Object
37 38 39 |
# File 'lib/device_wizard/user_agent_detector.rb', line 37 def unknown UNKNOWN end |