Module: RailsErrorDashboard::UserAgentHelper
- Defined in:
- app/helpers/rails_error_dashboard/user_agent_helper.rb
Instance Method Summary collapse
-
#browser_icon(browser_info) ⇒ Object
Get browser icon based on browser name.
-
#device_icon(browser_info) ⇒ Object
Get device icon based on device type.
-
#os_icon(browser_info) ⇒ Object
Get OS icon based on OS name.
-
#parse_user_agent(user_agent_string) ⇒ Object
Parse user agent string into browser, OS, and device info.
Instance Method Details
#browser_icon(browser_info) ⇒ Object
Get browser icon based on browser name
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/rails_error_dashboard/user_agent_helper.rb', line 27 def browser_icon(browser_info) return '<i class="bi bi-question-circle text-muted"></i>'.html_safe if browser_info.blank? case browser_info[:browser_name]&.downcase when "chrome" '<i class="bi bi-browser-chrome text-warning"></i>'.html_safe when "firefox" '<i class="bi bi-browser-firefox text-danger"></i>'.html_safe when "safari" '<i class="bi bi-browser-safari text-primary"></i>'.html_safe when "edge" '<i class="bi bi-browser-edge text-info"></i>'.html_safe else '<i class="bi bi-globe text-secondary"></i>'.html_safe end end |
#device_icon(browser_info) ⇒ Object
Get device icon based on device type
65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/rails_error_dashboard/user_agent_helper.rb', line 65 def device_icon(browser_info) return '<i class="bi bi-question-circle text-muted"></i>'.html_safe if browser_info.blank? if browser_info[:is_mobile] '<i class="bi bi-phone text-success"></i>'.html_safe elsif browser_info[:is_tablet] '<i class="bi bi-tablet text-info"></i>'.html_safe else '<i class="bi bi-laptop text-secondary"></i>'.html_safe end end |
#os_icon(browser_info) ⇒ Object
Get OS icon based on OS name
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/rails_error_dashboard/user_agent_helper.rb', line 45 def os_icon(browser_info) return '<i class="bi bi-question-circle text-muted"></i>'.html_safe if browser_info.blank? case browser_info[:os_name]&.downcase when /windows/ '<i class="bi bi-windows text-primary"></i>'.html_safe when /mac|darwin/ '<i class="bi bi-apple text-secondary"></i>'.html_safe when /linux/ '<i class="bi bi-ubuntu text-danger"></i>'.html_safe when /android/ '<i class="bi bi-android2 text-success"></i>'.html_safe when /ios|iphone|ipad/ '<i class="bi bi-apple text-secondary"></i>'.html_safe else '<i class="bi bi-cpu text-muted"></i>'.html_safe end end |
#parse_user_agent(user_agent_string) ⇒ Object
Parse user agent string into browser, OS, and device info
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/rails_error_dashboard/user_agent_helper.rb', line 6 def parse_user_agent(user_agent_string) return default_user_agent_info if user_agent_string.blank? browser = Browser.new(user_agent_string) { browser_name: browser_name(browser), browser_version: browser.version, os_name: os_name(browser), device_type: device_type(browser), platform: browser.platform.to_s.titleize, is_mobile: browser.device.mobile?, is_tablet: browser.device.tablet?, is_bot: browser.bot? } rescue StandardError => e Rails.logger.warn "[RailsErrorDashboard] Failed to parse user agent: #{e.}" default_user_agent_info end |