Class: UserAgent

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

Defined Under Namespace

Modules: ActionControllerAble

Constant Summary collapse

MOBILE_USER_AGENTS =
'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
'mobile'
MOBILE_USER_AGENTS_REGEXP =
::Regexp.new(MOBILE_USER_AGENTS)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ua = '') ⇒ UserAgent

Returns a new instance of UserAgent.



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

def initialize(ua='')
  @user_agent_string = ua.to_s.downcase
end

Instance Attribute Details

#user_agent_stringObject (readonly)

Returns the value of attribute user_agent_string.



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

def user_agent_string
  @user_agent_string
end

Instance Method Details

#device?(type) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/user_agent.rb', line 23

def device?(type)
  @user_agent_string.include?(type.to_s.downcase)
end

#mobile_device?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/user_agent.rb', line 19

def mobile_device?
  !!(@user_agent_string =~ MOBILE_USER_AGENTS_REGEXP)
end