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

- (MobileESP) initialize(detection_procedure = :mobile_desktop)

Creates a new instance of MobileESP strategy.

Parameters:

  • detection_procedure (defaults to: :mobile_desktop)

    a lambda function that gets one parameter (MobileESPConverted::UserAgentInfo instance) and returns device type symbol or nil.
    or
    a symbol for one of predefined detection procedures (:mobile_desktop, :mobile_tablet_desktop)



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

- (Symbol) get_device_type(request)

Gets device type using user-agent sniffing. Can return nil if the used detection procedure does so.

Parameters:

  • request (Rack::Request)

Returns:

  • (Symbol)

    device type or nil



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