Class: UserAgentParser::UserAgent
- Inherits:
-
Object
- Object
- UserAgentParser::UserAgent
- Defined in:
- lib/user_agent_parser/user_agent.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#family ⇒ Object
(also: #name)
readonly
Returns the value of attribute family.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(family = nil, version = nil, os = nil, device = nil) ⇒ UserAgent
constructor
A new instance of UserAgent.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(family = nil, version = nil, os = nil, device = nil) ⇒ UserAgent
Returns a new instance of UserAgent.
9 10 11 12 13 14 |
# File 'lib/user_agent_parser/user_agent.rb', line 9 def initialize(family = nil, version = nil, os = nil, device = nil) @family = family || 'Other' @version = version @os = os @device = device end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
5 6 7 |
# File 'lib/user_agent_parser/user_agent.rb', line 5 def device @device end |
#family ⇒ Object (readonly) Also known as: name
Returns the value of attribute family.
5 6 7 |
# File 'lib/user_agent_parser/user_agent.rb', line 5 def family @family end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
5 6 7 |
# File 'lib/user_agent_parser/user_agent.rb', line 5 def os @os end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/user_agent_parser/user_agent.rb', line 5 def version @version end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
29 30 31 32 33 34 |
# File 'lib/user_agent_parser/user_agent.rb', line 29 def eql?(other) self.class.eql?(other.class) && family == other.family && version == other.version && os == other.os end |
#inspect ⇒ Object
22 23 24 25 26 27 |
# File 'lib/user_agent_parser/user_agent.rb', line 22 def inspect string = to_s string += " (#{os})" if os string += " (#{device})" if device "#<#{self.class} #{string}>" end |
#to_h ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/user_agent_parser/user_agent.rb', line 38 def to_h { device: device.to_h, family: family, os: os.to_h, version: version.to_h } end |
#to_s ⇒ Object
16 17 18 19 20 |
# File 'lib/user_agent_parser/user_agent.rb', line 16 def to_s string = family string += " #{version}" if version string end |