browser 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "http://gems.simplesideias.com.br"
1
+ source :rubygems
2
2
  gemspec
@@ -1,38 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- browser (0.1.3)
4
+ browser (0.1.4)
5
5
 
6
6
  GEM
7
- remote: http://gems.simplesideias.com.br/
7
+ remote: http://rubygems.org/
8
8
  specs:
9
- abstract (1.0.0)
10
- actionpack (3.0.9)
11
- activemodel (= 3.0.9)
12
- activesupport (= 3.0.9)
13
- builder (~> 2.1.2)
14
- erubis (~> 2.6.6)
15
- i18n (~> 0.5.0)
16
- rack (~> 1.2.1)
17
- rack-mount (~> 0.6.14)
18
- rack-test (~> 0.5.7)
19
- tzinfo (~> 0.3.23)
20
- activemodel (3.0.9)
21
- activesupport (= 3.0.9)
22
- builder (~> 2.1.2)
23
- i18n (~> 0.5.0)
24
- activesupport (3.0.9)
25
- builder (2.1.2)
26
- erubis (2.6.6)
27
- abstract (>= 1.0.0)
28
- i18n (0.5.0)
29
- rack (1.2.3)
30
- rack-mount (0.6.14)
31
- rack (>= 1.0.0)
32
- rack-test (0.5.7)
9
+ actionpack (3.2.3)
10
+ activemodel (= 3.2.3)
11
+ activesupport (= 3.2.3)
12
+ builder (~> 3.0.0)
13
+ erubis (~> 2.7.0)
14
+ journey (~> 1.0.1)
15
+ rack (~> 1.4.0)
16
+ rack-cache (~> 1.2)
17
+ rack-test (~> 0.6.1)
18
+ sprockets (~> 2.1.2)
19
+ activemodel (3.2.3)
20
+ activesupport (= 3.2.3)
21
+ builder (~> 3.0.0)
22
+ activesupport (3.2.3)
23
+ i18n (~> 0.6)
24
+ multi_json (~> 1.0)
25
+ builder (3.0.0)
26
+ erubis (2.7.0)
27
+ hike (1.2.1)
28
+ i18n (0.6.0)
29
+ journey (1.0.3)
30
+ json (1.7.3)
31
+ multi_json (1.3.6)
32
+ rack (1.4.1)
33
+ rack-cache (1.2)
34
+ rack (>= 0.4)
35
+ rack-test (0.6.1)
33
36
  rack (>= 1.0)
34
- rake (0.9.2)
35
- tzinfo (0.3.29)
37
+ rake (0.9.2.2)
38
+ rdoc (3.12)
39
+ json (~> 1.4)
40
+ sprockets (2.1.3)
41
+ hike (~> 1.2)
42
+ rack (~> 1.0)
43
+ tilt (~> 1.1, != 1.3.0)
44
+ tilt (1.3.3)
36
45
 
37
46
  PLATFORMS
38
47
  ruby
@@ -41,3 +50,4 @@ DEPENDENCIES
41
50
  actionpack (~> 3.0)
42
51
  browser!
43
52
  rake (~> 0.9)
53
+ rdoc (~> 3.12)
@@ -14,6 +14,7 @@ Do some browser detection with Ruby. Includes ActionController integration.
14
14
  browser = Browser.new(:ua => "some string", :accept_language => "en-us")
15
15
  browser.safari?
16
16
  browser.opera?
17
+ browser.chrome?
17
18
  browser.mobile?
18
19
  browser.firefox?
19
20
  browser.ie?
data/Rakefile CHANGED
@@ -12,12 +12,13 @@ Rake::TestTask.new do |t|
12
12
  t.ruby_opts = %w[-rubygems]
13
13
  end
14
14
 
15
- require "rdoc/task"
16
- Rake::RDocTask.new do |rdoc|
15
+ require 'rdoc/task'
16
+ RDoc::Task.new do |rdoc|
17
17
  rdoc.main = "README.rdoc"
18
18
  rdoc.rdoc_dir = "doc"
19
19
  rdoc.title = "Browser API"
20
- rdoc.options += %w[ --line-numbers --inline-source --charset utf-8 ]
21
- rdoc.rdoc_files.include("README.rdoc")
22
- rdoc.rdoc_files.include("lib/**/*.rb")
20
+ rdoc.options += %w[ --line-numbers --charset utf-8 ]
21
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
23
22
  end
23
+
24
+ task :default => :test
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency "actionpack" , "~> 3.0"
21
21
  s.add_development_dependency "rake" , "~> 0.9"
22
+ s.add_development_dependency "rdoc" , "~> 3.12"
22
23
  end
@@ -28,9 +28,12 @@ class Browser
28
28
  :core_media => "Apple CoreMedia"
29
29
  }
30
30
 
31
- VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i
31
+ VERSIONS = {
32
+ :default => /(?:Version|MSIE|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i,
33
+ :opera => /Opera\/.*? Version\/([\d.]+)/
34
+ }
32
35
 
33
- COMPATIBILITY_VIEW_REGEXP = /Trident\/([0-9.]+)/
36
+ TRIDENT_VERSION_REGEX = /Trident\/([0-9.]+)/
34
37
 
35
38
  LANGUAGES = {
36
39
  "af" => "Afrikaans",
@@ -202,13 +205,7 @@ class Browser
202
205
 
203
206
  # Return the full version.
204
207
  def full_version
205
- if compatibility_view?
206
- _, v = *ua.match(COMPATIBILITY_VIEW_REGEXP)
207
- v.gsub!(/^([0-9])/) { $1.to_i + 4 }
208
- else
209
- _, v = *ua.match(VERSION_REGEX)
210
- end
211
-
208
+ _, v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
212
209
  v || "0.0"
213
210
  end
214
211
 
@@ -218,7 +215,7 @@ class Browser
218
215
  end
219
216
 
220
217
  def compatibility_view?
221
- ie? && ua.match(COMPATIBILITY_VIEW_REGEXP)
218
+ ie? && ua.match(TRIDENT_VERSION_REGEX) && version.to_i < ($1.to_i + 4)
222
219
  end
223
220
 
224
221
  # Detect if browser is WebKit-based.
@@ -336,6 +333,11 @@ class Browser
336
333
  !!(ua =~ /Linux/)
337
334
  end
338
335
 
336
+ # Detect if browser is tablet (currently just iPad or Android).
337
+ def tablet?
338
+ ipad? || (android? && !mobile?)
339
+ end
340
+
339
341
  # Return the platform.
340
342
  def platform
341
343
  case
@@ -2,7 +2,7 @@ class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 3
5
+ PATCH = 4
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -11,10 +11,11 @@ class BrowserTest < Test::Unit::TestCase
11
11
  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)"
12
12
  IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
13
13
  IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
14
- OPERA = "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9"
14
+ OPERA = "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64"
15
15
  FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
16
16
  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"
17
17
  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"
18
+ 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"
18
19
  BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
19
20
  PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
20
21
  QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
@@ -66,6 +67,7 @@ class BrowserTest < Test::Unit::TestCase
66
67
  assert @browser.mobile?
67
68
  assert @browser.capable?
68
69
  assert @browser.ios?
70
+ assert @browser.tablet? == false
69
71
  assert_equal "3.0", @browser.full_version
70
72
  assert_equal "3", @browser.version
71
73
  end
@@ -91,6 +93,7 @@ class BrowserTest < Test::Unit::TestCase
91
93
  assert @browser.mobile?
92
94
  assert @browser.capable?
93
95
  assert @browser.ios?
96
+ assert @browser.tablet? == false
94
97
  assert_equal "3.0", @browser.full_version
95
98
  assert_equal "3", @browser.version
96
99
  end
@@ -104,6 +107,7 @@ class BrowserTest < Test::Unit::TestCase
104
107
  assert @browser.webkit?
105
108
  assert @browser.capable?
106
109
  assert @browser.ios?
110
+ assert @browser.tablet?
107
111
  assert_equal "4.0.4", @browser.full_version
108
112
  assert_equal "4", @browser.version
109
113
  end
@@ -137,6 +141,7 @@ class BrowserTest < Test::Unit::TestCase
137
141
  assert @browser.ie?
138
142
  assert @browser.ie8?
139
143
  assert @browser.capable?
144
+ assert @browser.compatibility_view? == false
140
145
  assert_equal "8.0", @browser.full_version
141
146
  assert_equal "8", @browser.version
142
147
  end
@@ -146,11 +151,12 @@ class BrowserTest < Test::Unit::TestCase
146
151
 
147
152
  assert_equal "Internet Explorer", @browser.name
148
153
  assert @browser.ie?
149
- assert @browser.ie8?
154
+ assert @browser.ie7?
155
+ assert !@browser.ie8?
150
156
  assert @browser.capable?
151
157
  assert @browser.compatibility_view?
152
- assert_equal "8.0", @browser.full_version
153
- assert_equal "8", @browser.version
158
+ assert_equal "7.0", @browser.full_version
159
+ assert_equal "7", @browser.version
154
160
  end
155
161
 
156
162
  def test_detect_ie9
@@ -160,6 +166,7 @@ class BrowserTest < Test::Unit::TestCase
160
166
  assert @browser.ie?
161
167
  assert @browser.ie9?
162
168
  assert @browser.capable?
169
+ assert !@browser.compatibility_view?
163
170
  assert_equal "9.0", @browser.full_version
164
171
  assert_equal "9", @browser.version
165
172
  end
@@ -169,11 +176,12 @@ class BrowserTest < Test::Unit::TestCase
169
176
 
170
177
  assert_equal "Internet Explorer", @browser.name
171
178
  assert @browser.ie?
172
- assert @browser.ie9?
179
+ assert @browser.ie7?
180
+ assert !@browser.ie9?
173
181
  assert @browser.capable?
174
182
  assert @browser.compatibility_view?
175
- assert_equal "9.0", @browser.full_version
176
- assert_equal "9", @browser.version
183
+ assert_equal "7.0", @browser.full_version
184
+ assert_equal "7", @browser.version
177
185
  end
178
186
 
179
187
  def test_detect_opera
@@ -182,8 +190,8 @@ class BrowserTest < Test::Unit::TestCase
182
190
  assert_equal "Opera", @browser.name
183
191
  assert @browser.opera?
184
192
  assert @browser.capable?
185
- assert_equal "9.99", @browser.full_version
186
- assert_equal "9", @browser.version
193
+ assert_equal "11.64", @browser.full_version
194
+ assert_equal "11", @browser.version
187
195
  end
188
196
 
189
197
  def test_detect_firefox
@@ -216,16 +224,32 @@ class BrowserTest < Test::Unit::TestCase
216
224
  assert @browser.safari?
217
225
  assert @browser.webkit?
218
226
  assert @browser.mobile?
227
+ assert @browser.tablet? == false
219
228
  assert @browser.capable?
220
229
  assert_equal "3.1.2", @browser.full_version
221
230
  assert_equal "3", @browser.version
222
231
  end
223
232
 
233
+ def test_detect_android_tablet
234
+ @browser.ua = TABLOID
235
+
236
+ assert_equal "Android", @browser.name
237
+ assert @browser.android?
238
+ assert @browser.safari?
239
+ assert @browser.webkit?
240
+ assert @browser.mobile? == false
241
+ assert @browser.tablet?
242
+ assert @browser.capable?
243
+ assert_equal "4.0", @browser.full_version
244
+ assert_equal "4", @browser.version
245
+ end
246
+
224
247
  def test_detect_blackberry
225
248
  @browser.ua = BLACKBERRY
226
249
 
227
250
  assert_equal "BlackBerry", @browser.name
228
251
  assert @browser.blackberry?
252
+ assert @browser.tablet? == false
229
253
  assert @browser.mobile?
230
254
  assert @browser.capable? == false
231
255
  assert_equal "4.1.0", @browser.full_version
@@ -261,12 +285,16 @@ class BrowserTest < Test::Unit::TestCase
261
285
  def test_detect_other_mobiles
262
286
  @browser.ua = "Symbian OS"
263
287
  assert @browser.mobile?
288
+ assert @browser.tablet? == false
264
289
 
265
290
  @browser.ua = "MIDP-2.0"
266
291
  assert @browser.mobile?
292
+ assert @browser.tablet? == false
267
293
 
268
294
  @browser.ua = "Windows CE"
269
295
  assert @browser.mobile?
296
+ assert @browser.tablet? == false
297
+
270
298
  end
271
299
 
272
300
  def test_return_a_zero_version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-15 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &70196031340500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70196031340500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70196031339680 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,7 +37,28 @@ dependencies:
32
37
  version: '0.9'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70196031339680
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
36
62
  description: Do some browser detection with Ruby.
37
63
  email:
38
64
  - fnando.vieira@gmail.com
@@ -65,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
91
  version: '0'
66
92
  segments:
67
93
  - 0
68
- hash: 1304431903925043845
94
+ hash: 701530694838661058
69
95
  required_rubygems_version: !ruby/object:Gem::Requirement
70
96
  none: false
71
97
  requirements:
@@ -74,10 +100,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
100
  version: '0'
75
101
  segments:
76
102
  - 0
77
- hash: 1304431903925043845
103
+ hash: 701530694838661058
78
104
  requirements: []
79
105
  rubyforge_project:
80
- rubygems_version: 1.8.6
106
+ rubygems_version: 1.8.23
81
107
  signing_key:
82
108
  specification_version: 3
83
109
  summary: Do some browser detection with Ruby.