Permalink
Browse files

Added PSP support

  • Loading branch information...
1 parent 55df6e7 commit 293b09d898ff146af533d39aaa4bd11af798775c @tj committed Aug 28, 2009
Showing with 24 additions and 17 deletions.
  1. +1 −0 README.rdoc
  2. +20 −17 lib/user-agent/agent.rb
  3. +3 −0 spec/agents_spec.rb
View
1 README.rdoc
@@ -20,6 +20,7 @@ User agent parser.
* IE
* Konqueror
* PS3
+* PSP
* Wii
== License:
View
37 lib/user-agent/agent.rb
@@ -92,6 +92,7 @@ def self.version_for_user_agent string
when :Chrome ; $1 if string =~ /chrome\/([\d\w\.\-]+)/i
when :Safari ; $1 if string =~ /version\/([\d\w\.\-]+)/i
when :PS3 ; $1 if string =~ /([\d\w\.\-]+)\)\s*$/i
+ when :PSP ; $1 if string =~ /([\d\w\.\-]+)\)?\s*$/i
else $1 if string =~ /#{name}[\/ ]([\d\w\.\-]+)/i
end
end
@@ -117,16 +118,17 @@ def self.engine_for_user_agent string
def self.os_for_user_agent string
case string
- when /windows nt 6\.0/i ; :'Windows Vista'
- when /windows nt 6\.\d+/i ; :'Windows 7'
- when /windows nt 5\.2/i ; :'Windows 2003'
- when /windows nt 5\.1/i ; :'Windows XP'
- when /windows nt 5\.0/i ; :'Windows 2000'
- when /os x (\d+)[._](\d+)/i ; :"OS X #{$1}.#{$2}"
- when /linux/i ; :Linux
- when /wii/i ; :Wii
- when /playstation 3/i ; :Playstation
- else ; :Unknown
+ when /windows nt 6\.0/i ; :'Windows Vista'
+ when /windows nt 6\.\d+/i ; :'Windows 7'
+ when /windows nt 5\.2/i ; :'Windows 2003'
+ when /windows nt 5\.1/i ; :'Windows XP'
+ when /windows nt 5\.0/i ; :'Windows 2000'
+ when /os x (\d+)[._](\d+)/i ; :"OS X #{$1}.#{$2}"
+ when /linux/i ; :Linux
+ when /wii/i ; :Wii
+ when /playstation 3/i ; :Playstation
+ when /playstation portable/i ; :Playstation
+ else ; :Unknown
end
end
@@ -135,13 +137,14 @@ def self.os_for_user_agent string
def self.name_for_user_agent string
case string
- when /konqueror/i ; :Konqueror
- when /chrome/i ; :Chrome
- when /safari/i ; :Safari
- when /msie/i ; :IE
- when /opera/i ; :Opera
- when /playstation 3/i ; :PS3
- else ; :Unknown
+ when /konqueror/i ; :Konqueror
+ when /chrome/i ; :Chrome
+ when /safari/i ; :Safari
+ when /msie/i ; :IE
+ when /opera/i ; :Opera
+ when /playstation 3/i ; :PS3
+ when /playstation portable/i ; :PSP
+ else ; :Unknown
end
end
View
3 spec/agents_spec.rb
@@ -40,5 +40,8 @@ def test name, version, os, engine, engine_version, string
test :PS3, '2.00', :Playstation, :unknown, nil, 'Mozilla/5.0 (PLAYSTATION 3; 2.00)'
test :PS3, '1.10', :Playstation, :unknown, nil, 'Mozilla/5.0 (PLAYSTATION 3; 1.10)'
+
+ test :PSP, '2.00', :Playstation, :unknown, nil, 'PSP (PlayStation Portable); 2.00'
+ test :PSP, '2.00', :Playstation, :unknown, nil, 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'
end

0 comments on commit 293b09d

Please sign in to comment.