Class: Rack::Schmobile::UserAgents

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/schmobile/user_agents.rb

Constant Summary collapse

MOBILE_USER_AGENTS =
%w(
  alcatel amoi android astel audiovox blackberry cdm ce chtml danger docomo ericsson htc_touch
  iphone ipod j2me kddi midp minimo mmp mobi mobile mobileexplorer mot- motorola netfront nokia
  novarra palm pdxgw phone plucker pocket portable portalmmm sagem samsung sgh sie- softbank
  sprint symbian telit ucweb up.b upg1 vodafone webos windows x240 x320 xiino
)

Class Method Summary collapse

Class Method Details

.add_user_agent_pattern(pattern) ⇒ Object



17
18
19
20
# File 'lib/rack/schmobile/user_agents.rb', line 17

def self.add_user_agent_pattern(pattern)
  MOBILE_USER_AGENTS.push(*pattern)
  @mobile_agent_matcher = nil
end

.is_mobile_agent?(user_agent) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rack/schmobile/user_agents.rb', line 22

def self.is_mobile_agent?(user_agent)
  !(user_agent.to_s.downcase =~ mobile_agent_matcher).nil?
end

.mobile_agent_matcherObject



26
27
28
# File 'lib/rack/schmobile/user_agents.rb', line 26

def self.mobile_agent_matcher
  @mobile_agent_matcher ||= Regexp.new(MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join("|"))
end

.remove_user_agent_pattern(pattern) ⇒ Object



12
13
14
15
# File 'lib/rack/schmobile/user_agents.rb', line 12

def self.remove_user_agent_pattern(pattern)
  MOBILE_USER_AGENTS.delete(pattern)
  @mobile_agent_matcher = nil
end