class Schmobile::UserAgents

Constants

MOBILE_USER_AGENTS
NON_MOBILE_USER_AGENTS

Public Class Methods

add_non_mobile_user_agent_pattern(pattern) click to toggle source
# File lib/schmobile/user_agents.rb, line 30
def self.add_non_mobile_user_agent_pattern(pattern)
  NON_MOBILE_USER_AGENTS.push(*pattern)
  @non_mobile_agent_matcher = nil
end
add_user_agent_pattern(pattern) click to toggle source
# File lib/schmobile/user_agents.rb, line 20
def self.add_user_agent_pattern(pattern)
  MOBILE_USER_AGENTS.push(*pattern)
  @mobile_agent_matcher = nil
end
is_mobile_agent?(user_agent) click to toggle source
# File lib/schmobile/user_agents.rb, line 35
def self.is_mobile_agent?(user_agent)
  agent  = user_agent.to_s.downcase
  mobile = !(agent =~ mobile_agent_matcher).nil?
  mobile = mobile && agent !~ non_mobile_agent_matcher unless NON_MOBILE_USER_AGENTS.empty?
  mobile
end
matched_by?(user_agent) click to toggle source
# File lib/schmobile/user_agents.rb, line 50
def self.matched_by?(user_agent)
  MOBILE_USER_AGENTS.each do |agent|
    return agent if user_agent =~ /#{agent}/
  end
  nil
end
mobile_agent_matcher() click to toggle source
# File lib/schmobile/user_agents.rb, line 42
def self.mobile_agent_matcher
  @mobile_agent_matcher ||= Regexp.new(MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join('|'))
end
non_mobile_agent_matcher() click to toggle source
# File lib/schmobile/user_agents.rb, line 46
def self.non_mobile_agent_matcher
  @non_mobile_agent_matcher ||= Regexp.new(NON_MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join('|'))
end
remove_non_mobile_user_agent_pattern(pattern) click to toggle source
# File lib/schmobile/user_agents.rb, line 25
def self.remove_non_mobile_user_agent_pattern(pattern)
  NON_MOBILE_USER_AGENTS.delete(pattern)
  @non_mobile_agent_matcher = nil
end
remove_user_agent_pattern(pattern) click to toggle source
# File lib/schmobile/user_agents.rb, line 15
def self.remove_user_agent_pattern(pattern)
  MOBILE_USER_AGENTS.delete(pattern)
  @mobile_agent_matcher = nil
end