Class: UaUtils::OperatingSystem
- Inherits:
-
Object
- Object
- UaUtils::OperatingSystem
- Defined in:
- lib/ua-utils/operating_system.rb
Overview
The operating system that can be detected based on the user agent string.
Example
os = UaUtils::OperatingSystem.new(
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4')
if os.tablet?
(... do something for tablet devices ...)
end
if os.platform == :ios
render "/ios/show"
end
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
Instance Method Summary collapse
-
#desktop? ⇒ Boolean
Returns true if the operating system is a desktop device.
-
#initialize(user_agent_string) ⇒ OperatingSystem
constructor
Initializes operating system for parsing with the given user agent string.
-
#mobile? ⇒ Boolean
Returns true if the operating system is a mobile device.
-
#tablet? ⇒ Boolean
Returns true if the operating system is a tablet device.
-
#to_s ⇒ String
Returns string representation of the operating system.
-
#webtv? ⇒ Boolean
Returns true if the operating system is a webTV device.
Constructor Details
#initialize(user_agent_string) ⇒ OperatingSystem
Initializes operating system for parsing with the given user agent string.
23 24 25 |
# File 'lib/ua-utils/operating_system.rb', line 23 def initialize(user_agent_string) @platform, @device = detect_device(user_agent_string) end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
20 21 22 |
# File 'lib/ua-utils/operating_system.rb', line 20 def device @device end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
20 21 22 |
# File 'lib/ua-utils/operating_system.rb', line 20 def platform @platform end |
Instance Method Details
#desktop? ⇒ Boolean
Returns true if the operating system is a desktop device.
47 48 49 |
# File 'lib/ua-utils/operating_system.rb', line 47 def desktop? @device == :desktop end |
#mobile? ⇒ Boolean
Returns true if the operating system is a mobile device.
35 36 37 |
# File 'lib/ua-utils/operating_system.rb', line 35 def mobile? @device == :mobile end |
#tablet? ⇒ Boolean
Returns true if the operating system is a tablet device.
41 42 43 |
# File 'lib/ua-utils/operating_system.rb', line 41 def tablet? @device == :tablet end |
#to_s ⇒ String
Returns string representation of the operating system.
29 30 31 |
# File 'lib/ua-utils/operating_system.rb', line 29 def to_s @platform.to_s end |
#webtv? ⇒ Boolean
Returns true if the operating system is a webTV device.
53 54 55 |
# File 'lib/ua-utils/operating_system.rb', line 53 def webtv? @device == :webtv end |