Class: Mobvious::Strategies::MobileESP

Inherits:
Object
  • Object
show all
Defined in:
lib/mobvious/strategies/mobileesp.rb

Overview

Mobvious device detection strategy that uses user-agent sniffing provided by the MobileESP library.

Constant Summary

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 :tablet if mobileesp.is_tier_tablet
  return :desktop
}

Instance Method Summary collapse

Constructor Details

#initialize(detection_procedure = :mobile_desktop) ⇒ MobileESP

Creates a new instance of MobileESP strategy.



31
32
33
34
35
36
37
# File 'lib/mobvious/strategies/mobileesp.rb', line 31

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.



44
45
46
47
48
# File 'lib/mobvious/strategies/mobileesp.rb', line 44

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