Sha256: 659a3ceb18627add970eb39b6b6d6b8e58e9be8a8d1feb4c38c2ca4711d5b6bf

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module BrowserDetect
  module BrowserDetectHelper
  
    def browser_is? name
      
      name = name.to_s.strip
      
      return true if browser_name == name
      return true if name == 'mozilla' && browser_name == 'gecko'
      return true if name == 'ie' && browser_name.index('ie')
      return true if name == 'webkit' && browser_name == ('safari' or 'chrome' or 'iphone' or 'ipad')
    end
  
    def browser_name
      @browser_name ||= begin
  
        ua = request.env['HTTP_USER_AGENT'].downcase
        
        if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
          'ie'+ua[ua.index('msie')+5].chr
        elsif ua.index('gecko/') 
          'gecko'
        elsif ua.index('opera')
          'opera'
        elsif ua.index('konqueror') 
          'konqueror'
        elsif ua.index('ipad') 
          'ipad'
        elsif ua.index('iphone') 
          'iphone'
        elsif ua.index('chrome/')
          'chrome'
        elsif ua.index('applewebkit/')
          'safari'
        elsif ua.index('mozilla/')
          'gecko'
        end
      
      end
    end  
  
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
browser_detect-0.0.1 lib/browser_detect/browser_detect_helper.rb