Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added PS3 Support

  • Loading branch information...
commit 55df6e7d1a642eb8d609464fce38cfac834a1ee4 1 parent c3ff8be
@tj authored
Showing with 17 additions and 11 deletions.
  1. +1 −0  README.rdoc
  2. +13 −11 lib/user-agent/agent.rb
  3. +3 −0  spec/agents_spec.rb
View
1  README.rdoc
@@ -19,6 +19,7 @@ User agent parser.
* Opera
* IE
* Konqueror
+* PS3
* Wii
== License:
View
24 lib/user-agent/agent.rb
@@ -88,11 +88,11 @@ def self.engine_version_for_user_agent string
# 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
+ case name = name_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
+ else $1 if string =~ /#{name}[\/ ]([\d\w\.\-]+)/i
end
end
@@ -125,6 +125,7 @@ def self.os_for_user_agent string
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
end
end
@@ -134,12 +135,13 @@ 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
- 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
+ else ; :Unknown
end
end
View
3  spec/agents_spec.rb
@@ -38,4 +38,7 @@ def test name, version, os, engine, engine_version, string
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)'
+ 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)'
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.