Sha256: 4bb9cfc371318577cc3b5ab491ab27a6f9fc6120b135331439e6a47b78bfb604

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Rack
  module Schmobile
    class UserAgents

      MOBILE_USER_AGENTS = %w(
        alcatel amoi android astel audiovox blackberry cdm 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\ ce x240 x320 xiino
      )

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

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

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

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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schmobile-0.3.2 lib/rack/schmobile/user_agents.rb