Class: UserAgentParser::UserAgent

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

Constant Summary collapse

DEFAULT_FAMILY =
'Other'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(family = nil, version = nil, os = nil, device = nil) ⇒ UserAgent

Returns a new instance of UserAgent.



11
12
13
14
15
16
# File 'lib/user_agent_parser/user_agent.rb', line 11

def initialize(family = nil, version = nil, os = nil, device = nil)
  @family = family || DEFAULT_FAMILY
  @version = version
  @os = os
  @device = device
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



7
8
9
# File 'lib/user_agent_parser/user_agent.rb', line 7

def device
  @device
end

#familyObject (readonly) Also known as: name

Returns the value of attribute family.



7
8
9
# File 'lib/user_agent_parser/user_agent.rb', line 7

def family
  @family
end

#osObject (readonly)

Returns the value of attribute os.



7
8
9
# File 'lib/user_agent_parser/user_agent.rb', line 7

def os
  @os
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/user_agent_parser/user_agent.rb', line 7

def version
  @version
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/user_agent_parser/user_agent.rb', line 31

def eql?(other)
  self.class.eql?(other.class) &&
    family == other.family &&
    version == other.version &&
    os == other.os
end

#inspectObject



24
25
26
27
28
29
# File 'lib/user_agent_parser/user_agent.rb', line 24

def inspect
  string = to_s
  string += " (#{os})" if os
  string += " (#{device})" if device
  "#<#{self.class} #{string}>"
end

#to_hObject



40
41
42
43
44
45
46
47
# File 'lib/user_agent_parser/user_agent.rb', line 40

def to_h
  {
    device: device.to_h,
    family: family,
    os: os.to_h,
    version: version.to_h
  }
end

#to_sObject



18
19
20
21
22
# File 'lib/user_agent_parser/user_agent.rb', line 18

def to_s
  string = family
  string += " #{version}" if version
  string
end