Class: Mobvious::Strategies::URL
- Inherits:
-
Object
- Object
- Mobvious::Strategies::URL
- Defined in:
- lib/mobvious/strategies/url.rb
Overview
Mobvious device detection strategy that uses URL pattern matching.
Constant Summary collapse
- RULES_MOBILE_PATH =
Rule set with only one rule for domains that begin with
m.
matching as:mobile
. { /^\w+:\/\/m\./ => :mobile }
Instance Method Summary collapse
-
#get_device_type(request) ⇒ Symbol
Gets device type using URL pattern matching.
-
#initialize(rules = :mobile_path, options = {}) ⇒ URL
constructor
Creates a new URL strategy instance.
Constructor Details
#initialize(rules = :mobile_path, options = {}) ⇒ URL
Creates a new URL strategy instance.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mobvious/strategies/url.rb', line 23 def initialize(rules = :mobile_path, = {}) if rules.is_a? Symbol @rules = eval("RULES_#{rules.to_s.upcase}") else @rules = rules end = { disable_if_referer_set: false, disable_if_referer_matches: nil, disable_unless_referer_matches: nil } @options = .merge() end |
Instance Method Details
#get_device_type(request) ⇒ Symbol
Gets device type using URL pattern matching. Returns nil if no match found.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mobvious/strategies/url.rb', line 42 def get_device_type(request) return nil if disabled_by_referer_set?(request) || disabled_by_referer_matching?(request) || disabled_by_referer_not_matching?(request) @rules.each do |regex, device_type| return device_type if request.url =~ regex end nil end |