Permalink
Browse files

Added Konqueror support

  • Loading branch information...
tj committed Aug 28, 2009
1 parent 59e5dc9 commit c3ff8be756cd4e4d003754eed80a387109e521b9
Showing with 19 additions and 10 deletions.
  1. +2 −0 README.rdoc
  2. +13 −10 lib/user-agent/agent.rb
  3. +4 −0 spec/agents_spec.rb
View
@@ -15,8 +15,10 @@ User agent parser.
== Supported Agents
* Safari
+* Chrome
* Opera
* IE
+* Konqueror
* Wii
== License:
View
@@ -81,17 +81,18 @@ def == other
# Return engine version for user agent _string_.
def self.engine_version_for_user_agent string
- $1 if string =~ /#{engine_for_user_agent(string)}[\/ ]([\d\w\.]+)/i
+ $1 if string =~ /#{engine_for_user_agent(string)}[\/ ]([\d\w\.\-]+)/i
end
##
# Return version for user agent _string_.
def self.version_for_user_agent string
case string
- when /chrome/i ; $1 if string =~ /chrome\/([\d\w\.]+)/i
- when /safari/i ; $1 if string =~ /version\/([\d\w\.]+)/i
- else $1 if string =~ /#{name_for_user_agent(string)}[\/ ]([\d\w\.]+)/i
+ when /chrome/i ; $1 if string =~ /chrome\/([\d\w\.\-]+)/i
+ when /safari/i ; $1 if string =~ /version\/([\d\w\.\-]+)/i
+ else
+ $1 if string =~ /#{name_for_user_agent(string)}[\/ ]([\d\w\.\-]+)/i
end
end
@@ -100,8 +101,9 @@ def self.version_for_user_agent string
def self.engine_for_user_agent string
case string
- when /konqueror/i ; :konqueror
when /webkit/i ; :webkit
+ when /khtml/i ; :khtml
+ when /konqueror/i ; :konqueror
when /chrome/i ; :chrome
when /presto/i ; :presto
when /gecko/i ; :gecko
@@ -132,11 +134,12 @@ def self.os_for_user_agent string
def self.name_for_user_agent string
case string
- when /chrome/i ; :Chrome
- when /safari/i ; :Safari
- when /msie/i ; :IE
- when /opera/i ; :Opera
- else ; :Unknown
+ when /konqueror/i ; :Konqueror
+ when /chrome/i ; :Chrome
+ when /safari/i ; :Safari
+ when /msie/i ; :IE
+ when /opera/i ; :Opera
+ else ; :Unknown
end
end
View
@@ -34,4 +34,8 @@ def test name, version, os, engine, engine_version, string
test :Chrome, '4.0.202.2', :Linux, :webkit, '532.0', 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.2 Safari/532.0'
test :Chrome, '0.2.149.27', :'Windows 2003', :webkit, '525.13', 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13'
test :Chrome, '0.2.149.30', :'Windows Vista', :webkit, '525.13', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.30 Safari/525.13'
+
+ test :Konqueror, '4.2', :Linux, :khtml, '4.2.4', 'Mozilla/5.0 (compatible; Konqueror/4.2; Linux; X11; x86_64) KHTML/4.2.4 (like Gecko) Fedora/4.2.4-2.fc11'
+ test :Konqueror, '3.1-rc6', :Linux, :konqueror, '3.1-rc6', 'Mozilla/5.0 (compatible; Konqueror/3.1-rc6; i686 Linux; 20021105)'
+
end

0 comments on commit c3ff8be

Please sign in to comment.