Sha256: 692d2f69493d64d2ecb2713e401e23ca0cb1465e138324a5d70f532a212ee7dd

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

module Insightful
  module SystemHelper
    # check the current browser (via user agent) for the following:
    # :mozilla / :firefox
    # :ie6
    # :ie7
    # :ie
    # :iphone
    # :safari
    def browser_is? name
      name = name.to_s.strip

      return true if browser_name == name
      return true if (name == 'mozilla' or name == "firefox") && browser_name == 'gecko'
      return true if name == 'ie6' && browser_name.index('ie6')
      return true if name == 'ie7' && browser_name.index('ie7')
      return true if name == 'ie' && browser_name.index('ie')
      return true if name == 'iphone' && browser_name == 'iphone'
      return true if name == 'webkit' && browser_name == 'safari'
    end
  
    # find the current browser name
    def browser_name
      @browser_name ||= begin
        ua = request.user_agent.to_s.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('iphone')
          'iphone'
        elsif ua.index('applewebkit/')
          'safari'
        elsif ua.index('mozilla/')
          'gecko'
        else
          ""
        end
      end
    end
  
    def windows?
      # Can't match for just 'win' cause it will match darwin as well.
      (/win32|mswin|mingw/).match(RUBY_PLATFORM) ? true : false
    end

    # Works on Debian and Ubuntu, don't have anything else to test on.
    def linux?
      (/linux/).match(RUBY_PLATFORM) ? true : false
    end

    # Works on my MacBook Pro, don't have anything else to test on,
    def mac?
      (/darwin/).match(RUBY_PLATFORM) ? true : false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
insightful-0.0.1.6 lib/insightful/system_helper.rb
insightful-0.0.1.5 lib/insightful/system_helper.rb