Class: Schmobile::UserAgents
- Inherits:
-
Object
- Object
- Schmobile::UserAgents
- Defined in:
- lib/schmobile/user_agents.rb
Constant Summary collapse
- 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 )
- NON_MOBILE_USER_AGENTS =
%w( ipad )
Class Method Summary collapse
- .add_non_mobile_user_agent_pattern(pattern) ⇒ Object
- .add_user_agent_pattern(pattern) ⇒ Object
- .is_mobile_agent?(user_agent) ⇒ Boolean
- .matched_by?(user_agent) ⇒ Boolean
- .mobile_agent_matcher ⇒ Object
- .non_mobile_agent_matcher ⇒ Object
- .remove_non_mobile_user_agent_pattern(pattern) ⇒ Object
- .remove_user_agent_pattern(pattern) ⇒ Object
Class Method Details
.add_non_mobile_user_agent_pattern(pattern) ⇒ Object
30 31 32 33 |
# 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) ⇒ Object
20 21 22 23 |
# 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) ⇒ Boolean
35 36 37 38 39 40 |
# 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) ⇒ Boolean
50 51 52 53 54 55 |
# 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 ⇒ Object
42 43 44 |
# 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 ⇒ Object
46 47 48 |
# 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) ⇒ Object
25 26 27 28 |
# 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) ⇒ Object
15 16 17 18 |
# 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 |