Determines the name and version of the browser currently making a request.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2 commits ahead, 8 commits behind midas:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
History.txt
LICENSE
README.rdoc
Rakefile
VERSION
browser_detector.gemspec

README.rdoc

browser_detector

github.com/midas/browser_detector

DESCRIPTION

Determines the name and version of the browser currently making a request.

The browser detector uses the HTTP user agent string to determine which browser is making the current request. The detector can determine the name, version, major version, minor version, build version and revision version of the current browser.

If using Rails, there are several view helpers available that use the BrowserDetector: g_browser_name(), g_browser_version(), g_browser_full_name() and g_browser_is?().

FEATURES

  • Detector class that can determine the browser name and version given a user agent string.

  • List of known user agents.

  • List of example user agent strings for each known user agent.

INSTALL

gem sources -a http://gemcutter.org
sudo gem install

INSTALL FOR RAILS

Add to environment file:

config.gem "browser_detector", :version => '1.0.0', :source => 'http://gemcutter.org'

USAGE

The following examples will assume Firefox 3.5.3 on OS/X is being used. The user agent string for Firefox 3.5.3 on OS/X is:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3

Detector Class

@detector = BrowserDetector::Detector.new( request.env['HTTP_USER_AGENT'] )
puts @detector.browser_name # firefox
puts @detector.browser_version # 3.5.3
puts @detector.full_name # Firefox 3.5.3
puts @detector.browser_is? :name => :firefox, :version => '3.5.3' # true
puts @detector.browser_is? :name => :firefox, :major_version => 3, :minor_version => '5', build_version => '3' # true

Within Rails Views

g_browser_name

<% if g_browser_name == 'firefox' %>
  ...

g_browser_version

<% if g_browser_version == '3.5.3' %>
  ...

g_browser_full_name

<%= g_browser_full_name # Outputs: Firefox 3.5.3 %>

g_browser_is?

<% if g_browser_is?( :name => 'firefox', :version => '3.5.3' ) %>
  ...

<% if g_browser_is?( :name => 'firefox', :major_version => '3' ) %>
  ...

<% if g_browser_is?( :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3 ) %>
  ...

<% if g_browser_is?( :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3, :revision_version => 0 ) %>
  ...

LICENSE

(The MIT License)

Copyright © 2009 C. Jason Harrelson (midas)

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.