lib/rack/schmobile/user_agents.rb in schmobile-0.4.0 vs lib/rack/schmobile/user_agents.rb in schmobile-0.4.1

- old
+ new

@@ -21,12 +21,24 @@ def self.add_user_agent_pattern(pattern) MOBILE_USER_AGENTS.push(*pattern) @mobile_agent_matcher = nil end + def self.remove_non_mobile_user_agent_pattern(pattern) + NON_MOBILE_USER_AGENTS.delete(pattern) + @non_mobile_agent_matcher = nil + end + + def self.add_non_mobile_user_agent_pattern(pattern) + NON_MOBILE_USER_AGENTS.push(*pattern) + @non_mobile_agent_matcher = nil + end + def self.is_mobile_agent?(user_agent) - agent = user_agent.to_s.downcase - agent !~ non_mobile_agent_matcher && !(agent =~ mobile_agent_matcher).nil? + 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 def self.mobile_agent_matcher @mobile_agent_matcher ||= Regexp.new(MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join("|")) end