File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,22 @@ module Browser
44 class Platform
55 class IOS < Base
66 MATCHER = /(iPhone|iPad|iPod)/ . freeze
7- VERSION_MATCHER = /OS ([ \d .]+ )/ . freeze
7+ VERSION_MATCHER = /OS ((?<major> \d )_(?<minor> \d )_?(?<patch> \d )? )/ . freeze
88
99 def version
10- ua [ VERSION_MATCHER , 1 ] || "0"
10+ matches = VERSION_MATCHER . match ( ua )
11+
12+ return "0" unless matches
13+
14+ versions = [ matches [ :major ] ]
15+
16+ if matches [ :patch ]
17+ versions . push ( matches [ :minor ] , matches [ :patch ] )
18+ else
19+ versions . push ( matches [ :minor ] ) unless matches [ :minor ] == "0"
20+ end
21+
22+ versions . join ( "." )
1123 end
1224
1325 def name
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ IOS5: "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46
6363IOS6 : " 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"
6464IOS7 : " Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"
6565IOS8 : " Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4"
66+ IOS8_1_2 : ' Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4'
67+ IOS8_3 : ' Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4'
6668IOS9 : " Mozilla/5.0 (iPad; CPU OS 9_0 like Mac OS X) AppleWebKit/601.1.17 (KHTML, like Gecko) Version/8.0 Mobile/13A175 Safari/600.1.4"
6769IOS_WEBVIEW : Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H141
6870IPAD : " 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"
Original file line number Diff line number Diff line change @@ -62,6 +62,27 @@ def id
6262 assert_equal "9" , platform . version
6363 end
6464
65+ test "detect specific minor iOS (iPhone)" do
66+ platform = Browser ::Platform . new ( Browser [ "IOS8_3" ] )
67+
68+ assert_equal "iOS (iPhone)" , platform . name
69+ assert_equal :ios , platform . id
70+ assert platform . ios?
71+ assert platform . ios? ( 8.3 )
72+ assert_equal "8.3" , platform . version
73+ end
74+
75+ test "detect specific patch iOS (iPhone)" do
76+ platform = Browser ::Platform . new ( Browser [ "IOS8_1_2" ] )
77+
78+ assert_equal "iOS (iPhone)" , platform . name
79+ assert_equal :ios , platform . id
80+ assert platform . ios?
81+ assert platform . ios? ( "8.1.2" )
82+ assert platform . ios? ( "<8.2" )
83+ assert_equal "8.1.2" , platform . version
84+ end
85+
6586 test "detect ios (iPod Touch)" do
6687 platform = Browser ::Platform . new ( Browser [ "IPOD" ] )
6788
You can’t perform that action at this time.
0 commit comments