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 +1 -1
- data/Gemfile.lock +38 -28
- data/README.rdoc +1 -0
- data/Rakefile +6 -5
- data/browser.gemspec +1 -0
- data/lib/browser.rb +12 -10
- data/lib/browser/version.rb +1 -1
- data/test/browser_test.rb +37 -9
- metadata +35 -9
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source :rubygems
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
browser (0.1.
|
4
|
+
browser (0.1.4)
|
5
5
|
|
6
6
|
GEM
|
7
|
-
remote: http://
|
7
|
+
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rack (~> 1.2
|
17
|
-
rack-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
i18n (~> 0.
|
24
|
-
|
25
|
-
builder (
|
26
|
-
erubis (2.
|
27
|
-
|
28
|
-
i18n (0.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
rack
|
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
|
-
|
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)
|
data/README.rdoc
CHANGED
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
|
16
|
-
|
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 --
|
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
|
data/browser.gemspec
CHANGED
data/lib/browser.rb
CHANGED
@@ -28,9 +28,12 @@ class Browser
|
|
28
28
|
:core_media => "Apple CoreMedia"
|
29
29
|
}
|
30
30
|
|
31
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
data/lib/browser/version.rb
CHANGED
data/test/browser_test.rb
CHANGED
@@ -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.
|
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.
|
154
|
+
assert @browser.ie7?
|
155
|
+
assert !@browser.ie8?
|
150
156
|
assert @browser.capable?
|
151
157
|
assert @browser.compatibility_view?
|
152
|
-
assert_equal "
|
153
|
-
assert_equal "
|
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.
|
179
|
+
assert @browser.ie7?
|
180
|
+
assert !@browser.ie9?
|
173
181
|
assert @browser.capable?
|
174
182
|
assert @browser.compatibility_view?
|
175
|
-
assert_equal "
|
176
|
-
assert_equal "
|
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 "
|
186
|
-
assert_equal "
|
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.
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
103
|
+
hash: 701530694838661058
|
78
104
|
requirements: []
|
79
105
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.23
|
81
107
|
signing_key:
|
82
108
|
specification_version: 3
|
83
109
|
summary: Do some browser detection with Ruby.
|