From f9cdd1605ecf2471904650788907f5124ea334a1 Mon Sep 17 00:00:00 2001 From: visionmedia Date: Fri, 28 Aug 2009 11:42:50 -0700 Subject: [PATCH] Added Opera support --- lib/user-agent/agent.rb | 6 ++++-- spec/agents_spec.rb | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/user-agent/agent.rb b/lib/user-agent/agent.rb index 7510e36..e217cd7 100644 --- a/lib/user-agent/agent.rb +++ b/lib/user-agent/agent.rb @@ -89,8 +89,9 @@ def self.engine_version_for_user_agent string def self.version_for_user_agent string case string - when /safari/i ; $1 if string =~ /Version\/([\d\w\.]+)/i - when /msie/i ; $1 if string =~ /MSIE\s*([\d\w\.]+)/i + when /safari/i ; $1 if string =~ /version\/([\d\w\.]+)/i + when /msie/i ; $1 if string =~ /msie\s*([\d\w\.]+)/i + when /opera/i ; $1 if string =~ /opera[\/ ]([\d\w\.]+)/i end end @@ -133,6 +134,7 @@ def self.name_for_user_agent string when /chrome/i ; :Chrome when /safari/i ; :Safari when /msie/i ; :IE + when /opera/i ; :Opera else ; :Unknown end end diff --git a/spec/agents_spec.rb b/spec/agents_spec.rb index bde37e4..2080dfc 100644 --- a/spec/agents_spec.rb +++ b/spec/agents_spec.rb @@ -11,7 +11,7 @@ ['4.0', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru-RU) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16'], ['3.2.3', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.29'], ].each do |version, string| - it "should parse version '#{version}'" do + it "should parse version #{version}" do Agent.new(string).name.should == :Safari Agent.new(string).version.should == version end @@ -28,11 +28,29 @@ ['6.0', 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'], ].each do |version, string| unless version.empty? - it "should parse version '#{version}'" do + it "should parse version #{version}" do Agent.new(string).name.should == :IE Agent.new(string).version.should == version end end end end + + describe "Opera" do + [ + ['9.99', 'Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9'], + ['9.70', 'Mozilla/5.0 (Linux i686 ; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.70'], + ['9.64', 'Opera/9.64 (X11; Linux i686; U; Linux Mint; it) Presto/2.1.1'], + ['9.51', 'Mozilla/5.0 (X11; Linux i686; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.51'], + ['9.00', 'Opera/9.00 (Nintindo Wii; U; ; 103858; Wii Shop Channel/1.0; en)'], + ].each do |version, string| + unless version.empty? + it "should parse version #{version}" do + Agent.new(string).name.should == :Opera + Agent.new(string).version.should == version + end + end + end + end + end \ No newline at end of file