browser 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f90b0344537f71e69a359b33edbcebe06ee932f
4
- data.tar.gz: 6e6caba603576500ab20f2b643be80904fc5e1d1
3
+ metadata.gz: 0e085e2a4794cd3e1368120c6f574b7c15cb6f3c
4
+ data.tar.gz: cb7bc7aea7519f258b72ddf8cca00a35b1e7e58f
5
5
  SHA512:
6
- metadata.gz: 75b78cc40248cc1a32c0acc7c92a4ea7375acc1a9324d2a1120d6538a217bf9c3b2fce3de825516dba71375ee76005db283fe91f44f4dea627b92781f9097e23
7
- data.tar.gz: 580e766794ff26827365750195a2f42e068b745a28f531744f0b2116526a5bbf7f3d0956bd02d4cbd27cf7e2fa4e30296e53b6d44327e1777d158247a7b7c965
6
+ metadata.gz: cd8ef682213aa133b315233165f20b6e8ecd6670805c85e4916d62411a78a62cb00a767289de30ee421b2f4f87e7dc10596ff11b55f1b5443c210471e29e0f0e
7
+ data.tar.gz: e3007ffbba33bfd98f82190892d1b1ed163c4d97249df9e9d0a640398ebe103e59c08b7b1c43c0b68c573a353f8a640636be1659d9cc0db06e6ba85982dc9d80
data/.travis.yml CHANGED
@@ -4,5 +4,5 @@ rvm:
4
4
  - 2.0.0
5
5
  - jruby-19mode
6
6
  gemfile:
7
+ - Gemfile
7
8
  - gemfiles/rails3.gemfile
8
- - gemfiles/rails4.gemfile
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- browser (0.2.0)
4
+ browser (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -19,6 +19,7 @@ require "browser"
19
19
 
20
20
  browser = Browser.new(:ua => "some string", :accept_language => "en-us")
21
21
  browser.name # readable browser name
22
+ browser.version
22
23
  browser.safari?
23
24
  browser.opera?
24
25
  browser.chrome?
@@ -1,17 +1,17 @@
1
1
  PATH
2
- remote: /mnt/hgfs/!%Projects/github/browser
2
+ remote: /mnt/hgfs/-Projects/github/browser
3
3
  specs:
4
- browser (0.2.0)
4
+ browser (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionmailer (3.2.13)
10
- actionpack (= 3.2.13)
11
- mail (~> 2.5.3)
12
- actionpack (3.2.13)
13
- activemodel (= 3.2.13)
14
- activesupport (= 3.2.13)
9
+ actionmailer (3.2.14)
10
+ actionpack (= 3.2.14)
11
+ mail (~> 2.5.4)
12
+ actionpack (3.2.14)
13
+ activemodel (= 3.2.14)
14
+ activesupport (= 3.2.14)
15
15
  builder (~> 3.0.0)
16
16
  erubis (~> 2.7.0)
17
17
  journey (~> 1.0.4)
@@ -19,19 +19,19 @@ GEM
19
19
  rack-cache (~> 1.2)
20
20
  rack-test (~> 0.6.1)
21
21
  sprockets (~> 2.2.1)
22
- activemodel (3.2.13)
23
- activesupport (= 3.2.13)
22
+ activemodel (3.2.14)
23
+ activesupport (= 3.2.14)
24
24
  builder (~> 3.0.0)
25
- activerecord (3.2.13)
26
- activemodel (= 3.2.13)
27
- activesupport (= 3.2.13)
25
+ activerecord (3.2.14)
26
+ activemodel (= 3.2.14)
27
+ activesupport (= 3.2.14)
28
28
  arel (~> 3.0.2)
29
29
  tzinfo (~> 0.3.29)
30
- activeresource (3.2.13)
31
- activemodel (= 3.2.13)
32
- activesupport (= 3.2.13)
33
- activesupport (3.2.13)
34
- i18n (= 0.6.1)
30
+ activeresource (3.2.14)
31
+ activemodel (= 3.2.14)
32
+ activesupport (= 3.2.14)
33
+ activesupport (3.2.14)
34
+ i18n (~> 0.6, >= 0.6.4)
35
35
  multi_json (~> 1.0)
36
36
  arel (3.0.2)
37
37
  awesome_print (1.1.0)
@@ -39,15 +39,15 @@ GEM
39
39
  coderay (1.0.9)
40
40
  erubis (2.7.0)
41
41
  hike (1.2.3)
42
- i18n (0.6.1)
42
+ i18n (0.6.5)
43
43
  journey (1.0.4)
44
44
  json (1.8.0)
45
45
  mail (2.5.4)
46
46
  mime-types (~> 1.16)
47
47
  treetop (~> 1.4.8)
48
- method_source (0.8.1)
49
- mime-types (1.23)
50
- multi_json (1.7.7)
48
+ method_source (0.8.2)
49
+ mime-types (1.25)
50
+ multi_json (1.8.0)
51
51
  polyglot (0.3.3)
52
52
  pry (0.9.12.2)
53
53
  coderay (~> 1.0.5)
@@ -70,17 +70,17 @@ GEM
70
70
  rack
71
71
  rack-test (0.6.2)
72
72
  rack (>= 1.0)
73
- rails (3.2.13)
74
- actionmailer (= 3.2.13)
75
- actionpack (= 3.2.13)
76
- activerecord (= 3.2.13)
77
- activeresource (= 3.2.13)
78
- activesupport (= 3.2.13)
73
+ rails (3.2.14)
74
+ actionmailer (= 3.2.14)
75
+ actionpack (= 3.2.14)
76
+ activerecord (= 3.2.14)
77
+ activeresource (= 3.2.14)
78
+ activesupport (= 3.2.14)
79
79
  bundler (~> 1.0)
80
- railties (= 3.2.13)
81
- railties (3.2.13)
82
- actionpack (= 3.2.13)
83
- activesupport (= 3.2.13)
80
+ railties (= 3.2.14)
81
+ railties (3.2.14)
82
+ actionpack (= 3.2.14)
83
+ activesupport (= 3.2.14)
84
84
  rack-ssl (~> 1.3.2)
85
85
  rake (>= 0.8.7)
86
86
  rdoc (~> 3.4)
@@ -88,7 +88,7 @@ GEM
88
88
  rake (10.1.0)
89
89
  rdoc (3.12.2)
90
90
  json (~> 1.4)
91
- slop (3.4.5)
91
+ slop (3.4.6)
92
92
  sprockets (2.2.2)
93
93
  hike (~> 1.2)
94
94
  multi_json (~> 1.0)
@@ -96,7 +96,7 @@ GEM
96
96
  tilt (~> 1.1, != 1.3.0)
97
97
  thor (0.18.1)
98
98
  tilt (1.4.1)
99
- treetop (1.4.14)
99
+ treetop (1.4.15)
100
100
  polyglot
101
101
  polyglot (>= 0.3.1)
102
102
  tzinfo (0.3.37)
data/lib/browser.rb CHANGED
@@ -100,7 +100,8 @@ class Browser
100
100
  webkit? ||
101
101
  (firefox? && version.to_i >= 17) ||
102
102
  (ie? && version.to_i >= 9) ||
103
- (opera? && version.to_i >= 12)
103
+ (opera? && version.to_i >= 12) ||
104
+ (firefox? && tablet? && android? && version.to_i >= 14)
104
105
  end
105
106
 
106
107
  # Detect if browser is WebKit-based.
@@ -143,6 +144,11 @@ class Browser
143
144
  !!(ua =~ /(Opera|OPR)/)
144
145
  end
145
146
 
147
+ # Detect if browser is Silk.
148
+ def silk?
149
+ !!(ua =~ /Silk/)
150
+ end
151
+
146
152
  # Return a meta info about this browser.
147
153
  def meta
148
154
  Meta.constants.each_with_object(Set.new) do |meta_name, meta|
@@ -15,19 +15,28 @@ class Browser
15
15
  !!(ua =~ /iPod/)
16
16
  end
17
17
 
18
- # Detect if browser is tablet (currently just iPad or Android).
18
+ def surface?
19
+ windows_rt? && !!(ua =~ /Touch/)
20
+ end
21
+
22
+ # Detect if browser is tablet (currently iPad, Android, Surface or Playbook).
19
23
  def tablet?
20
- !!(ipad? || (android? && !detect_mobile?))
24
+ !!(ipad? || (android? && !detect_mobile?) || surface? || playbook?)
21
25
  end
22
26
 
23
27
  # Detect if browser is Kindle.
24
28
  def kindle?
25
- !!(ua =~ /Kindle/)
29
+ !!(ua =~ /Kindle/ || silk?)
26
30
  end
27
31
 
28
32
  # Detect if browser is running from PSP.
29
33
  def psp?
30
34
  !!(ua =~ /PSP/)
31
35
  end
36
+
37
+ # Detect if browser if a Blackberry Playbook tablet
38
+ def playbook?
39
+ !!(ua =~ /PlayBook/ and ua =~ /RIM Tablet/)
40
+ end
32
41
  end
33
42
  end
@@ -34,6 +34,14 @@ class Browser
34
34
  def windows?
35
35
  !!(ua =~ /Windows/)
36
36
  end
37
+
38
+ def windows8?
39
+ windows? && !!(ua =~ /Windows NT 6.2/)
40
+ end
41
+
42
+ def windows_rt?
43
+ windows8? && !!(ua =~ /ARM/)
44
+ end
37
45
 
38
46
  # Detect if current platform is Linux flavor.
39
47
  def linux?
@@ -2,7 +2,7 @@ require "uri"
2
2
 
3
3
  class Browser
4
4
  class Middleware
5
- attr_reader :env, :request
5
+ attr_reader :env
6
6
 
7
7
  def initialize(app, &block)
8
8
  raise ArgumentError, "Browser::Middleware requires a block" unless block
@@ -13,19 +13,19 @@ class Browser
13
13
 
14
14
  def call(env)
15
15
  @env = env
16
- @request = Rack::Request.new(env)
16
+ request = Rack::Request.new(env)
17
17
 
18
18
  path = catch(:redirected) do
19
19
  Context.new(request).instance_eval(&@block)
20
20
  end
21
21
 
22
- path ? resolve_redirection(path) : run_app!
22
+ path ? resolve_redirection(request.path, path) : run_app!
23
23
  end
24
24
 
25
- def resolve_redirection(path)
25
+ def resolve_redirection(current_path, path)
26
26
  uri = URI.parse(path)
27
27
 
28
- if uri.path == request.path
28
+ if uri.path == current_path
29
29
  run_app!
30
30
  else
31
31
  redirect(path)
@@ -2,7 +2,7 @@ class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/test/browser_test.rb CHANGED
@@ -2,43 +2,49 @@
2
2
  require "test_helper"
3
3
 
4
4
  class BrowserTest < Test::Unit::TestCase
5
- IPHONE = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"
6
- IPOD = "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3"
7
- IPAD = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"
8
- SAFARI = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8"
9
- IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
10
- IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
11
- IE8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
12
- IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
13
- IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
14
- IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
15
- IE10 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)"
16
- IE10_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; EIE10;ENUSMSN)"
17
- OPERA = "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64"
18
- OPERA_NEXT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.37 Safari/537.36 OPR/15.0.1147.44 (Edition Next)"
19
- FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
20
- FIREFOX_MODERN = "Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:17.0) Gecko/20100101 Firefox/17.0"
21
- CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
22
- MOBILE_CHROME = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
23
- ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
24
- TABLOID = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13"
25
- BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
26
- PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
27
- QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
28
- COREMEDIA = "Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569"
29
- XOOM = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13"
30
- NEXUS_TABLET = "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"
31
- NOOK = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; NOOK BNTV250A Build/GINGERBREAD 1.4.3) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1"
32
- SAMSUNG = "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; SAMSUNG-SGH-I497 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30"
33
- OPERA_MINI = "Opera/9.80 (Android; Opera Mini/7.029952/28.2359;u; fr) Presto/2.8.119 Version/11.10"
34
- OPERA_MOBI = "Opera/9.8 (Android 2.3.5; Linux; Opera Mobi/ADR-1205181138; U; en) Presto/2.10.254 Version/12.00"
35
- WINDOWS_PHONE = "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)"
36
- KINDLE = "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)"
37
- KINDLE_FIRE = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
38
- PHANTOM_JS = "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.0 Safari/534.34"
39
- IOS4 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"
40
- IOS5 = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
41
- IOS6 = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
5
+ IPHONE = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"
6
+ IPOD = "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3"
7
+ IPAD = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"
8
+ SAFARI = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8"
9
+ IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
10
+ IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
11
+ IE8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
12
+ IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
13
+ IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
14
+ IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
15
+ IE10 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)"
16
+ IE10_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; EIE10;ENUSMSN)"
17
+ OPERA = "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64"
18
+ OPERA_NEXT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.37 Safari/537.36 OPR/15.0.1147.44 (Edition Next)"
19
+ FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
20
+ FIREFOX_MODERN = "Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:17.0) Gecko/20100101 Firefox/17.0"
21
+ FIREFOX_TABLET = "Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0"
22
+ CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
23
+ MOBILE_CHROME = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
24
+ ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
25
+ TABLOID = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13"
26
+ BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
27
+ PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
28
+ QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
29
+ COREMEDIA = "Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569"
30
+ XOOM = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13"
31
+ NEXUS_TABLET = "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"
32
+ NOOK = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; NOOK BNTV250A Build/GINGERBREAD 1.4.3) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1"
33
+ SAMSUNG = "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; SAMSUNG-SGH-I497 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30"
34
+ OPERA_MINI = "Opera/9.80 (Android; Opera Mini/7.029952/28.2359;u; fr) Presto/2.8.119 Version/11.10"
35
+ OPERA_MOBI = "Opera/9.8 (Android 2.3.5; Linux; Opera Mobi/ADR-1205181138; U; en) Presto/2.10.254 Version/12.00"
36
+ WINDOWS_PHONE = "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)"
37
+ WINDOWS_PHONE8 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"
38
+ SURFACE = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)"
39
+ KINDLE = "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)"
40
+ KINDLE_FIRE = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
41
+ KINDLE_FIRE_HD = "Mozilla/5.0 (Linux; U; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Safari/535.19 Silk-Accelerated=true"
42
+ KINDLE_FIRE_HD_MOBILE = "Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Mobile Safari/535.19 Silk-Accelerated=true"
43
+ PHANTOM_JS = "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.0 Safari/534.34"
44
+ IOS4 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"
45
+ IOS5 = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
46
+ IOS6 = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
47
+ PLAYBOOK = "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+"
42
48
 
43
49
  def setup
44
50
  @browser = Browser.new
@@ -291,6 +297,18 @@ class BrowserTest < Test::Unit::TestCase
291
297
  assert_equal "17", @browser.version
292
298
  end
293
299
 
300
+ def test_detect_firefox_android_tablet
301
+ @browser.ua = FIREFOX_TABLET
302
+
303
+ assert_equal "Android", @browser.name
304
+ assert @browser.firefox?
305
+ assert @browser.modern?
306
+ assert @browser.tablet?
307
+ assert @browser.android?
308
+ assert_equal "14.0", @browser.full_version
309
+ assert_equal "14", @browser.version
310
+ end
311
+
294
312
  def test_detect_chrome
295
313
  @browser.ua = CHROME
296
314
 
@@ -343,6 +361,19 @@ class BrowserTest < Test::Unit::TestCase
343
361
  assert_equal "4", @browser.version
344
362
  end
345
363
 
364
+ def test_detect_surface_tablet
365
+ @browser.ua = SURFACE
366
+
367
+ assert_equal "Internet Explorer", @browser.name
368
+ assert @browser.surface?
369
+ assert @browser.ie?
370
+ assert ! @browser.mobile?
371
+ assert @browser.tablet?
372
+ assert @browser.modern?
373
+ assert_equal "10.0", @browser.full_version
374
+ assert_equal "10", @browser.version
375
+ end
376
+
346
377
  def test_detect_blackberry
347
378
  @browser.ua = BLACKBERRY
348
379
 
@@ -537,6 +568,17 @@ class BrowserTest < Test::Unit::TestCase
537
568
  assert ! @browser.mobile?
538
569
  end
539
570
 
571
+ def test_blackberry_playbook_tablet
572
+ @browser.ua = PLAYBOOK
573
+
574
+ assert ! @browser.android?
575
+ assert @browser.tablet?
576
+ assert ! @browser.mobile?
577
+
578
+ assert_equal "7.2.1.0", @browser.full_version
579
+ assert_equal "7", @browser.version
580
+ end
581
+
540
582
  def test_opera_mini
541
583
  @browser.ua = OPERA_MINI
542
584
 
@@ -562,6 +604,15 @@ class BrowserTest < Test::Unit::TestCase
562
604
  assert ! @browser.tablet?
563
605
  end
564
606
 
607
+ def test_windows_phone_8
608
+ @browser.ua = WINDOWS_PHONE8
609
+
610
+ assert @browser.ie?
611
+ assert_equal "10", @browser.version
612
+ assert @browser.mobile?
613
+ assert ! @browser.tablet?
614
+ end
615
+
565
616
  def test_kindle_monochrome
566
617
  @browser.ua = KINDLE
567
618
 
@@ -576,6 +627,26 @@ class BrowserTest < Test::Unit::TestCase
576
627
  assert @browser.webkit?
577
628
  end
578
629
 
630
+ def test_kindle_fire_hd
631
+ @browser.ua = KINDLE_FIRE_HD
632
+
633
+ assert @browser.silk?
634
+ assert @browser.kindle?
635
+ assert @browser.webkit?
636
+ assert @browser.modern?
637
+ assert ! @browser.mobile?
638
+ end
639
+
640
+ def test_kindle_fire_hd_mobile
641
+ @browser.ua = KINDLE_FIRE_HD_MOBILE
642
+
643
+ assert @browser.silk?
644
+ assert @browser.kindle?
645
+ assert @browser.webkit?
646
+ assert @browser.modern?
647
+ assert @browser.mobile?
648
+ end
649
+
579
650
  def test_nook
580
651
  @browser.ua = NOOK
581
652
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-29 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-meta
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.0.3
118
+ rubygems_version: 2.1.0
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Do some browser detection with Ruby.