browser 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rcov/rcovtask"
2
2
  require "rake/testtask"
3
3
  require "rake/rdoctask"
4
- require "lib/browser/version"
4
+ require "./lib/browser/version"
5
5
 
6
6
  Rcov::RcovTask.new do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
@@ -21,7 +21,9 @@ class Browser
21
21
  :iphone => "iPhone",
22
22
  :ipod => "iPod Touch",
23
23
  :opera => "Opera",
24
- :other => "Other"
24
+ :other => "Other",
25
+ :safari => "Safari",
26
+ :psp => "PlayStation Portable"
25
27
  }
26
28
 
27
29
  LANGUAGES = {
@@ -173,6 +175,8 @@ class Browser
173
175
  when firefox? then :firefox
174
176
  when android? then :android
175
177
  when blackberry? then :blackberry
178
+ when safari? then :safari
179
+ when psp? then :psp
176
180
  else
177
181
  :other
178
182
  end
@@ -199,9 +203,14 @@ class Browser
199
203
  safari? || firefox? || opera? || (ie? && version >= "7")
200
204
  end
201
205
 
206
+ # Detect if browser is WebKit-based.
207
+ def webkit?
208
+ !!(ua =~ /AppleWebKit/i)
209
+ end
210
+
202
211
  # Detect if browser is mobile.
203
212
  def mobile?
204
- !!(ua =~ /(Mobile|Symbian|MIDP|Windows CE)/) || blackberry?
213
+ !!(ua =~ /(Mobile|Symbian|MIDP|Windows CE)/) || blackberry? || psp?
205
214
  end
206
215
 
207
216
  # Detect if browser is BlackBerry
@@ -269,6 +278,11 @@ class Browser
269
278
  ie? && version == "9"
270
279
  end
271
280
 
281
+ # Detect if browser is running from PSP.
282
+ def psp?
283
+ !!(ua =~ /PSP/)
284
+ end
285
+
272
286
  # Detect if browser is Opera.
273
287
  def opera?
274
288
  !!(ua =~ /Opera/)
@@ -304,7 +318,7 @@ class Browser
304
318
  def meta
305
319
  Array.new.tap do |m|
306
320
  m << id
307
- m << "safari safari#{version}" if safari?
321
+ m << "webkit safari safari#{version}" if safari?
308
322
  m << "#{id}#{version}" unless safari?
309
323
  m << platform
310
324
  m << "capable" if capable?
@@ -7,8 +7,8 @@ class Browser
7
7
  private
8
8
  def browser
9
9
  @browser ||= Browser.new(
10
- :accept_language => request.headers["ACCEPT_LANGUAGE"],
11
- :ua => request.headers["USER_AGENT"]
10
+ :accept_language => request.headers["Accept-Language"],
11
+ :ua => request.headers["User-Agent"]
12
12
  )
13
13
  end
14
14
  end
@@ -2,7 +2,7 @@ class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -14,6 +14,7 @@ class BrowserTest < Test::Unit::TestCase
14
14
  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"
15
15
  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"
16
16
  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"
17
+ 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"
17
18
  IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
18
19
  IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
19
20
  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)"
@@ -23,6 +24,7 @@ class BrowserTest < Test::Unit::TestCase
23
24
  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"
24
25
  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
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)"
26
28
 
27
29
  def setup
28
30
  @browser = Browser.new
@@ -66,18 +68,31 @@ class BrowserTest < Test::Unit::TestCase
66
68
  assert_equal "iPhone", @browser.name
67
69
  assert @browser.iphone?
68
70
  assert @browser.safari?
71
+ assert @browser.webkit?
69
72
  assert @browser.mobile?
70
73
  assert @browser.capable?
71
74
  assert_equal "3.0", @browser.full_version
72
75
  assert_equal "3", @browser.version
73
76
  end
74
77
 
78
+ def test_detect_safari
79
+ @browser.ua = SAFARI
80
+
81
+ assert_equal "Safari", @browser.name
82
+ assert @browser.safari?
83
+ assert @browser.webkit?
84
+ assert @browser.capable?
85
+ assert_equal "5.0.1", @browser.full_version
86
+ assert_equal "5", @browser.version
87
+ end
88
+
75
89
  def test_detect_ipod
76
90
  @browser.ua = IPOD
77
91
 
78
92
  assert_equal "iPod Touch", @browser.name
79
93
  assert @browser.ipod?
80
94
  assert @browser.safari?
95
+ assert @browser.webkit?
81
96
  assert @browser.mobile?
82
97
  assert @browser.capable?
83
98
  assert_equal "3.0", @browser.full_version
@@ -90,6 +105,7 @@ class BrowserTest < Test::Unit::TestCase
90
105
  assert_equal "iPad", @browser.name
91
106
  assert @browser.ipad?
92
107
  assert @browser.safari?
108
+ assert @browser.webkit?
93
109
  assert @browser.capable?
94
110
  assert_equal "4.0.4", @browser.full_version
95
111
  assert_equal "4", @browser.version
@@ -165,6 +181,7 @@ class BrowserTest < Test::Unit::TestCase
165
181
  assert_equal "Chrome", @browser.name
166
182
  assert @browser.chrome?
167
183
  assert @browser.safari?
184
+ assert @browser.webkit?
168
185
  assert @browser.capable?
169
186
  assert_equal "5.0.375.99", @browser.full_version
170
187
  assert_equal "5", @browser.version
@@ -176,6 +193,7 @@ class BrowserTest < Test::Unit::TestCase
176
193
  assert_equal "Android", @browser.name
177
194
  assert @browser.android?
178
195
  assert @browser.safari?
196
+ assert @browser.webkit?
179
197
  assert @browser.mobile?
180
198
  assert @browser.capable?
181
199
  assert_equal "3.1.2", @browser.full_version
@@ -193,6 +211,14 @@ class BrowserTest < Test::Unit::TestCase
193
211
  assert_equal "4", @browser.version
194
212
  end
195
213
 
214
+ def test_detect_psp
215
+ @browser.ua = PSP
216
+
217
+ assert_equal "PlayStation Portable", @browser.name
218
+ assert @browser.psp?
219
+ assert @browser.mobile?
220
+ end
221
+
196
222
  def test_detect_other_mobiles
197
223
  @browser.ua = "Symbian OS"
198
224
  assert @browser.mobile?
@@ -217,12 +243,12 @@ class BrowserTest < Test::Unit::TestCase
217
243
 
218
244
  def test_return_string_representation
219
245
  @browser.ua = CHROME
220
- assert_equal "chrome safari safari5 mac capable", @browser.to_s
246
+ assert_equal "chrome webkit safari safari5 mac capable", @browser.to_s
221
247
  end
222
248
 
223
249
  def test_return_string_representation_for_mobile
224
250
  @browser.ua = IPHONE
225
- assert_equal "iphone safari safari3 mac capable mobile", @browser.to_s
251
+ assert_equal "iphone webkit safari safari3 mac capable mobile", @browser.to_s
226
252
  end
227
253
 
228
254
  def test_return_string_representation_for_handcap
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 0
10
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Nando Vieira
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-07-16 00:00:00 -03:00
17
+ date: 2010-10-13 00:00:00 -03:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -48,7 +47,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
47
  requirements:
49
48
  - - ">="
50
49
  - !ruby/object:Gem::Version
51
- hash: 3
52
50
  segments:
53
51
  - 0
54
52
  version: "0"
@@ -57,7 +55,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  requirements:
58
56
  - - ">="
59
57
  - !ruby/object:Gem::Version
60
- hash: 3
61
58
  segments:
62
59
  - 0
63
60
  version: "0"