Class: Hello::Utils::DeviceName

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hello/utils/device_name.rb

Instance Method Summary collapse

Instance Method Details

#parse(user_agent_string) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hello/utils/device_name.rb', line 10

def parse(user_agent_string)
  obj = user_agent_parser.parse(user_agent_string)
  a_browser = obj.to_s
  a_os = obj.os.to_s
  a_browser = "#{obj.name} #{obj.version && obj.version.major}".strip
  a_os = "#{obj.os.name} #{obj.os.version && obj.os.version.major}".strip
  a_device = obj.device.name

  a_browser = a_browser.gsub('IE', 'Internet Explorer') if a_browser.start_with? 'IE'

  if a_device == 'Other'
    "#{a_os} - #{a_browser}"
  elsif a_device == 'Spider'
    "Spider: #{a_browser}"
  else
    "#{a_os} (#{a_device}) - #{a_browser}"
  end.strip
end

#user_agent_parserObject



29
30
31
# File 'lib/hello/utils/device_name.rb', line 29

def user_agent_parser
  @uap = UserAgentParser::Parser.new
end