Module: ActiveDevice

Defined in:
lib/active_device.rb,
lib/active_device_helper.rb

Defined Under Namespace

Modules: Helper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



35
36
37
38
39
40
# File 'lib/active_device.rb', line 35

def self.included(base)
  base.before_filter :set_mobile_format
  base.helper_method :is_mobile_device?, :is_mobile_browser?, :is_desktop_browser?, :is_bot?
  base.helper_method :is_mobile_view?
  base.helper_method :is_device?, :is_handset?, :is_brand?, :is_model?, :is_os?, :is_engine?, :is_browser?
end

Instance Method Details

#is_bot?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a bot in our regex.

Returns:

  • (Boolean)


83
84
85
# File 'lib/active_device.rb', line 83

def is_bot?
  Bot.is_bot? request.user_agent
end

#is_brand?(brand) ⇒ Boolean

Can check for a specific brand e.g., is_brand?(‘Nokia’) or is_brand?(‘HTC’)

Returns:

  • (Boolean)


104
105
106
# File 'lib/active_device.rb', line 104

def is_brand? brand
  Handset.is_brand? request.user_agent, brand
end

#is_browser?(browser) ⇒ Boolean

Can check for a specific user agent e.g., is_browser?(‘Firefox’) or is_browser?(‘Chrome’)

Returns:

  • (Boolean)


132
133
134
# File 'lib/active_device.rb', line 132

def is_browser? browser
  Browser.is_browser? request.user_agent, browser
end

#is_desktop_browser?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.

Returns:

  • (Boolean)


76
77
78
# File 'lib/active_device.rb', line 76

def is_desktop_browser?
  !Handset.is_mobile? request.user_agent
end

#is_device?(type) ⇒ Boolean

Can check for a specific type e.g., is_device?(‘iphone’) or is_device?(‘mobileexplorer’)

Returns:

  • (Boolean)


90
91
92
# File 'lib/active_device.rb', line 90

def is_device? type
  request.user_agent.to_s.downcase.include?(type.to_s.downcase)
end

#is_engine?(engine) ⇒ Boolean

Can check for a specific Engine e.g., is_engine?(‘Webkit’) or is_engine?(‘Chrome’)

Returns:

  • (Boolean)


125
126
127
# File 'lib/active_device.rb', line 125

def is_engine? engine
  Engine.is_engine? request.user_agent, engine
end

#is_handset?(type) ⇒ Boolean

Can check for a specific type e.g., is_handset?(‘iphone’) or is_handset?(‘mobileexplorer’)

Returns:

  • (Boolean)


97
98
99
# File 'lib/active_device.rb', line 97

def is_handset? type
  Handset.is_handset? request.user_agent, type
end

#is_mobile_browser?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.

Returns:

  • (Boolean)


69
70
71
# File 'lib/active_device.rb', line 69

def is_mobile_browser?
  Handset.is_mobile? request.user_agent
end

#is_mobile_device?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.

Returns:

  • (Boolean)


62
63
64
# File 'lib/active_device.rb', line 62

def is_mobile_device?
  Handset.is_mobile? request.user_agent
end

#is_mobile_view?Boolean

Returns either true or false depending on whether or not the format of the request is either :mobile or not.

Returns:

  • (Boolean)


55
56
57
# File 'lib/active_device.rb', line 55

def is_mobile_view?
  request.format.to_sym == :mobile
end

#is_model?(model) ⇒ Boolean

Can check for a specific Mobile Model e.g., is_model?(‘NokiaE72’) or is_model?(‘Nokia6630’)

Returns:

  • (Boolean)


111
112
113
# File 'lib/active_device.rb', line 111

def is_model? model
  Handset.is_model? request.user_agent, model
end

#is_os?(os) ⇒ Boolean

Can check for a specific OS e.g., is_os?(‘SymbianOS’) or is_os?(‘Linux’)

Returns:

  • (Boolean)


118
119
120
# File 'lib/active_device.rb', line 118

def is_os? os
  Os.is_os? request.user_agent, os
end

#set_mobile_formatObject

Determines the request format based on whether the device is mobile or if the user has opted to use either the ‘Standard’ view or ‘Mobile’ view.



45
46
47
48
49
50
# File 'lib/active_device.rb', line 45

def set_mobile_format
  if is_mobile_device?
    request.format = session[:mobile_view] == false ? :html : :mobile
    session[:mobile_view] = true if session[:mobile_view].nil?
  end
end