Sha256: f460f78e08a3cf7ce75e75f77db8bf2ba27b379a17cee9b0f50124b07aab676d

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

require 'nitro/context'

module Nitro

module Request

  # Some useful mini methods for browser testing.
  # TODO: add testing for mac IE (an other platforms)

  # Different servers hold user agent in differnet 
  # strings (unify this).
  
  def user_agent
    headers['HTTP_USER_AGENT'] || headers['USER-AGENT']
  end

  def from_gecko?
    user_agent =~ /Gecko/
  end
  alias_method :from_mozilla?, :from_gecko?

  def from_ie?
    user_agent =~ /MSIE/
  end
  alias_method :from_msie?, :from_ie?

  def from_opera?
    user_agent =~ /Opera/
  end

  def from_khtml?
    puts "agent = #{user_agent}"
    user_agent =~ /KHTML/
  end
  alias_method :from_safari?, :from_khtml?

  def from_w3c?
    from_gecko? or from_khtml? or from_opera?
  end
  
  def from_osx?
    user_agent =~ /Mac OS X/ or user_agent =~ /Mac_PowerPC/
  end

  def from_os9?
  end
  
  def from_mac?
    from_osx? or from_os9?
  end
  
  def from_unix?
    user_agent =~ /linux/ or user_agent =~ /FreeBSD/
  end
  alias_method :from_linux?, :from_unix?
  
  def from_windows?
    user_agent =~ /Windows/
  end

end

end

# * Chris Farmiloe <chris.farmiloe@farmiloe.com>

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nitro-0.41.0 lib/nitro/cgi/utils.rb
nitro-0.28.0 lib/nitro/cgi/utils.rb
nitro-0.29.0 lib/nitro/cgi/utils.rb
nitro-0.27.0 lib/nitro/cgi/utils.rb
nitro-0.30.0 lib/nitro/cgi/utils.rb
nitro-0.31.0 lib/nitro/cgi/utils.rb
nitro-0.40.0 lib/nitro/cgi/utils.rb