Module: ActiveDevice
- Includes:
- Helper
- Defined in:
- lib/active_device/helper.rb,
lib/active_device.rb,
lib/active_device/version.rb
Overview
– Copyright © 2009 Shenouda Bertel <[email protected]>, MobiThought.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Defined Under Namespace
Modules: Helper
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#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.
-
#is_brand?(brand) ⇒ Boolean
Can check for a specific brand e.g., is_brand?(‘Nokia’) or is_brand?(‘HTC’).
-
#is_browser?(browser) ⇒ Boolean
Can check for a specific user agent e.g., is_browser?(‘Firefox’) or is_browser?(‘Chrome’).
-
#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.
-
#is_device?(type) ⇒ Boolean
Can check for a specific type e.g., is_device?(‘iphone’) or is_device?(‘mobileexplorer’).
-
#is_engine?(engine) ⇒ Boolean
Can check for a specific Engine e.g., is_engine?(‘Webkit’) or is_engine?(‘Chrome’).
-
#is_handset?(type) ⇒ Boolean
Can check for a specific type e.g., is_handset?(‘iphone’) or is_handset?(‘mobileexplorer’).
-
#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.
-
#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.
-
#is_mobile_view? ⇒ Boolean
Returns either true or false depending on whether or not the format of the request is either :mobile or not.
-
#is_model?(model) ⇒ Boolean
Can check for a specific Mobile Model e.g., is_model?(‘NokiaE72’) or is_model?(‘Nokia6630’).
-
#is_os?(os) ⇒ Boolean
Can check for a specific OS e.g., is_os?(‘SymbianOS’) or is_os?(‘Linux’).
-
#set_mobile_format ⇒ Object
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.
Methods included from Helper
#agent_engine, #agent_engine_version, #agent_name, #agent_os, #agent_os_series, #agent_os_version, #agent_version, #device_brand, #device_model, #device_model_reselution
Class Method Details
.included(base) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/active_device.rb', line 38 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.
86 87 88 |
# File 'lib/active_device.rb', line 86 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’)
107 108 109 |
# File 'lib/active_device.rb', line 107 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’)
135 136 137 |
# File 'lib/active_device.rb', line 135 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.
79 80 81 |
# File 'lib/active_device.rb', line 79 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’)
93 94 95 |
# File 'lib/active_device.rb', line 93 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’)
128 129 130 |
# File 'lib/active_device.rb', line 128 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’)
100 101 102 |
# File 'lib/active_device.rb', line 100 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.
72 73 74 |
# File 'lib/active_device.rb', line 72 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.
65 66 67 |
# File 'lib/active_device.rb', line 65 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.
58 59 60 |
# File 'lib/active_device.rb', line 58 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’)
114 115 116 |
# File 'lib/active_device.rb', line 114 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’)
121 122 123 |
# File 'lib/active_device.rb', line 121 def is_os? os Os.is_os? request.user_agent, os end |
#set_mobile_format ⇒ Object
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.
48 49 50 51 52 53 |
# File 'lib/active_device.rb', line 48 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 |