Class: RailsErrorDashboard::Services::PlatformDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/services/platform_detector.rb

Overview

Detects the platform (iOS/Android/API) from user agent string. Uses the browser gem when available, falls back to regex matching.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent) ⇒ PlatformDetector

Returns a new instance of PlatformDetector.



12
13
14
# File 'lib/rails_error_dashboard/services/platform_detector.rb', line 12

def initialize(user_agent)
  @user_agent = user_agent
end

Class Method Details

.detect(user_agent) ⇒ Object



8
9
10
# File 'lib/rails_error_dashboard/services/platform_detector.rb', line 8

def self.detect(user_agent)
  new(user_agent).detect
end

Instance Method Details

#detectObject



16
17
18
19
20
21
22
23
24
# File 'lib/rails_error_dashboard/services/platform_detector.rb', line 16

def detect
  return "API" if @user_agent.blank?

  if defined?(Browser)
    detect_with_browser_gem
  else
    detect_with_regex
  end
end