Class: Mobvious::Strategies::MobileESP
- Inherits:
-
Object
- Object
- Mobvious::Strategies::MobileESP
- Defined in:
- lib/mobvious/strategies/mobileesp.rb
Overview
Mobvious device detection strategy that uses user-agent sniffing provided by the MobileESP library.
Constant Summary collapse
- DEVICE_TYPES_MOBILE_DESKTOP =
Detection procedure that classifies mobile phones as
:mobile
and anything else as:desktop
. lambda {|mobileesp| return :mobile if mobileesp.is_tier_generic_mobile || mobileesp.is_tier_iphone || mobileesp.is_tier_rich_css return :desktop }
- DEVICE_TYPES_MOBILE_TABLET_DESKTOP =
Detection procedure that classifies mobile phones as
:mobile
, tablets as:tablet
and anything else as:desktop
. lambda {|mobileesp| return :mobile if mobileesp.is_tier_generic_mobile || mobileesp.is_tier_iphone || mobileesp.is_tier_rich_css return :mobile if mobileesp.is_tier_generic_mobile || mobileesp.is_tier_iphone return :tablet if mobileesp.is_tier_tablet return :desktop }
Instance Method Summary collapse
-
#get_device_type(request) ⇒ Symbol
Gets device type using user-agent sniffing.
-
#initialize(detection_procedure = :mobile_desktop) ⇒ MobileESP
constructor
Creates a new instance of MobileESP strategy.
Constructor Details
#initialize(detection_procedure = :mobile_desktop) ⇒ MobileESP
Creates a new instance of MobileESP strategy.
32 33 34 35 36 37 38 |
# File 'lib/mobvious/strategies/mobileesp.rb', line 32 def initialize(detection_procedure = :mobile_desktop) if detection_procedure.is_a? Symbol @detection_procedure = eval("DEVICE_TYPES_#{detection_procedure.to_s.upcase}") else @detection_procedure = detection_procedure end end |
Instance Method Details
#get_device_type(request) ⇒ Symbol
Gets device type using user-agent sniffing. Can return nil if the used detection procedure does so.
45 46 47 48 49 |
# File 'lib/mobvious/strategies/mobileesp.rb', line 45 def get_device_type(request) return nil if request.user_agent.nil? || request.env['HTTP_ACCEPT'].nil? mobileesp = MobileESPConverted::UserAgentInfo.new(request.user_agent, request.env['HTTP_ACCEPT']) @detection_procedure.call(mobileesp) end |