Class: UaUtils::OperatingSystem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#deviceObject (readonly)

Returns the value of attribute device.



20
21
22
# File 'lib/ua-utils/operating_system.rb', line 20

def device
  @device
end

#platformObject (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


41
42
43
# File 'lib/ua-utils/operating_system.rb', line 41

def tablet?
  @device == :tablet
end

#to_sString

Returns string representation of the operating system.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/ua-utils/operating_system.rb', line 53

def webtv?
  @device == :webtv
end