Class: UseragentParser::UserAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/useragent_parser/user_agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(details = {}) ⇒ UserAgent

Returns a new instance of UserAgent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/useragent_parser/user_agent.rb', line 7

def initialize(details = {})
  if user_agent = details['user_agent']
    @browser_family = user_agent['family'] || 'Other'
    @browser_major_version = user_agent['major']
    @browser_minor_version = user_agent['minor']
    @browser_patch_version = user_agent['patch']
  end

  if os = details['os']
    @os_family = os['family'] || 'Other'
    @os_major_version = os['major']
    @os_minor_version = os['minor']
    @os_patch_version = os['patch']
  end

   if device = details['device']
     @device = device['family']
     @is_mobile = device['is_mobile']
     @is_spider = device['is_spider']
   end

   if referrer = details['referrer']
    @webmail_client = referrer['family']
  end
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser
  @browser
end

#browser_familyObject (readonly)

Returns the value of attribute browser_family.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser_family
  @browser_family
end

#browser_major_versionObject (readonly)

Returns the value of attribute browser_major_version.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser_major_version
  @browser_major_version
end

#browser_minor_versionObject (readonly)

Returns the value of attribute browser_minor_version.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser_minor_version
  @browser_minor_version
end

#browser_patch_versionObject (readonly)

Returns the value of attribute browser_patch_version.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser_patch_version
  @browser_patch_version
end

#browser_versionObject (readonly)

Returns the value of attribute browser_version.



3
4
5
# File 'lib/useragent_parser/user_agent.rb', line 3

def browser_version
  @browser_version
end

#osObject (readonly)

Returns the value of attribute os.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os
  @os
end

#os_familyObject (readonly)

Returns the value of attribute os_family.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os_family
  @os_family
end

#os_major_versionObject (readonly)

Returns the value of attribute os_major_version.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os_major_version
  @os_major_version
end

#os_minor_versionObject (readonly)

Returns the value of attribute os_minor_version.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os_minor_version
  @os_minor_version
end

#os_patch_versionObject (readonly)

Returns the value of attribute os_patch_version.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os_patch_version
  @os_patch_version
end

#os_version(options = {}) ⇒ Object (readonly)

Returns the value of attribute os_version.



4
5
6
# File 'lib/useragent_parser/user_agent.rb', line 4

def os_version
  @os_version
end

#webmail_clientObject (readonly)

Returns the value of attribute webmail_client.



5
6
7
# File 'lib/useragent_parser/user_agent.rb', line 5

def webmail_client
  @webmail_client
end

Instance Method Details

#deviceObject



33
34
35
# File 'lib/useragent_parser/user_agent.rb', line 33

def device
  @device
end

#emailObject



77
78
79
# File 'lib/useragent_parser/user_agent.rb', line 77

def email
  @email ||= email_name
end

#email_versionObject



81
82
83
# File 'lib/useragent_parser/user_agent.rb', line 81

def email_version
  @email_version ||= email_version_name
end

#is_email?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/useragent_parser/user_agent.rb', line 85

def is_email?
  is_outlook? || is_ios_mail? || is_apple_mail? || is_desktop_email? || is_webmail?
end

#is_mobile?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/useragent_parser/user_agent.rb', line 37

def is_mobile?
  !!@is_mobile
end

#is_spider?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/useragent_parser/user_agent.rb', line 41

def is_spider?
  !!@is_spider
end

#os_family_aggregatedObject



66
67
68
69
70
71
# File 'lib/useragent_parser/user_agent.rb', line 66

def os_family_aggregated
  case os_family
  when 'Windows', 'Windows NT' then 'Windows'
  else os_family
  end
end