class Rack::SmartphoneDetector

Constants

SMARTPHONE_IDENTIFIERS
VERSION
VERSION_PATTERNS

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/rack/smartphone_detector.rb, line 23
def initialize(app, options = {})
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/smartphone_detector.rb, line 27
def call(env)
  SMARTPHONE_IDENTIFIERS.each do |i|
    if env['HTTP_USER_AGENT'] =~ i[:regexp]
      env['rack.smartphone_detector.device'] = i[:identifier]
      detect_version(env, i[:version_type])
      break
    end
  end
  @app.call(env)
end

Private Instance Methods

detect_version(env, version_type) click to toggle source
# File lib/rack/smartphone_detector.rb, line 40
def detect_version(env, version_type)
  if env['HTTP_USER_AGENT'] =~ VERSION_PATTERNS[version_type]
    env['rack.smartphone_detector.device_version'] = Regexp.last_match[1]
  end
end