Skip to content

Commit

Permalink
Added PSP support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 28, 2009
1 parent 55df6e7 commit 293b09d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.rdoc
Expand Up @@ -20,6 +20,7 @@ User agent parser.
* IE
* Konqueror
* PS3
* PSP
* Wii

== License:
Expand Down
37 changes: 20 additions & 17 deletions lib/user-agent/agent.rb
Expand Up @@ -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
Expand All @@ -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

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

Expand Down
3 changes: 3 additions & 0 deletions spec/agents_spec.rb
Expand Up @@ -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.