Skip to content

Commit

Permalink
Added Konqueror support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 28, 2009
1 parent 59e5dc9 commit c3ff8be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ User agent parser.
== Supported Agents

* Safari
* Chrome
* Opera
* IE
* Konqueror
* Wii

== License:
Expand Down
23 changes: 13 additions & 10 deletions lib/user-agent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/agents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.