Class: UaUtils::UserAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/ua-utils/user_agent.rb

Overview

The user agent object.

Example

user_agent = UaUtils::UserAgent.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 user_agent.os.tablet?
 (... do something for tablet devices ...)
end

if user_agent.os.platform == :ios
  render "/ios/show"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent_string) ⇒ UserAgent

Initializes a user agent for parsing with a given user agent string

Parameters:

  • user_agent_string (Object)


24
25
26
# File 'lib/ua-utils/user_agent.rb', line 24

def initialize(user_agent_string)
  @user_agent_string = user_agent_string
end

Instance Attribute Details

#osUaUtils::OperatingSystem (readonly)

Returns operating system of the user agent.

Returns:



30
31
32
# File 'lib/ua-utils/user_agent.rb', line 30

def os
  @os
end