Class: UserAgentParser::UserAgent

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

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.



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

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

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



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

def device
  @device
end

#familyObject (readonly) Also known as: name

Returns the value of attribute family.



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

def family
  @family
end

#osObject (readonly)

Returns the value of attribute os.



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

def os
  @os
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

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

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/user_agent_parser/user_agent.rb', line 27

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

#inspectObject



20
21
22
23
24
25
# File 'lib/user_agent_parser/user_agent.rb', line 20

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

#to_sObject



14
15
16
17
18
# File 'lib/user_agent_parser/user_agent.rb', line 14

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