class DeviceWizard::UserAgentDetector
Constants
- ANDROID
- IPAD
- IPHONE
- MOBILE
CONST Keywords
- REGEX_CRAWLER
- REGEX_MOBILE
- REGEX_OS
CONST Regex Patterns
- SILK
- TABLET
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
get_browser(user_agent)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/device_wizard/user_agent_detector.rb, line 37 def unknown UNKNOWN end
Private Instance Methods
determine_type(user_agent)
click to toggle source
# File lib/device_wizard/user_agent_detector.rb, line 84 def determine_type(user_agent) return DeviceType::TABLET if user_agent.include? TABLET 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 return DeviceType::MOBILE if REGEX_MOBILE =~ user_agent return DeviceType::TABLET if user_agent.include? SILK return DeviceType::DESKTOP if REGEX_OS =~ user_agent return DeviceType::CRAWLER if REGEX_CRAWLER =~ user_agent end