Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added CoreMedia detection.

  • Loading branch information...
commit ac24ea20c715a7b44a1cac28f90f4586e14104fd 1 parent 5931410
@fnando authored
Showing with 21 additions and 2 deletions.
  1. +11 −2 lib/browser.rb
  2. +10 −0 test/browser_test.rb
View
13 lib/browser.rb
@@ -24,9 +24,12 @@ class Browser
:other => "Other",
:safari => "Safari",
:psp => "PlayStation Portable",
- :quicktime => "QuickTime"
+ :quicktime => "QuickTime",
+ :core_media => "Apple CoreMedia"
}
+ VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i
+
LANGUAGES = {
"af" => "Afrikaans",
"sq" => "Albanian",
@@ -179,6 +182,7 @@ def id
when safari? then :safari
when psp? then :psp
when quicktime? then :quicktime
+ when core_media? then :core_media
else
:other
end
@@ -196,7 +200,7 @@ def version
# Return the full version.
def full_version
- _, v = *ua.match(/(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+)[\/ ]([\d.]+)/)
+ _, v = *ua.match(VERSION_REGEX)
v || "0.0"
end
@@ -230,6 +234,11 @@ def android?
!!(ua =~ /Android/)
end
+ # Detect if browser is Apple CoreMedia.
+ def core_media?
+ !!(ua =~ /CoreMedia/)
+ end
+
# Detect if browser is iPhone.
def iphone?
!!(ua =~ /iPhone/)
View
10 test/browser_test.rb
@@ -26,6 +26,7 @@ class BrowserTest < Test::Unit::TestCase
BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
+ COREMEDIA = "Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569"
def setup
@browser = Browser.new
@@ -221,6 +222,15 @@ def test_detect_quicktime
assert_equal "7", @browser.version
end
+ def test_detect_core_media
+ @browser.ua = COREMEDIA
+
+ assert_equal "Apple CoreMedia", @browser.name
+ assert @browser.core_media?
+ assert_equal "1.0.0.10F569", @browser.full_version
+ assert_equal "1", @browser.version
+ end
+
def test_detect_psp
@browser.ua = PSP
Please sign in to comment.
Something went wrong with that request. Please try again.