user_agent_sanitizer 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,10 +8,20 @@ Example:
8
8
  require 'user_agent_sanitizer'
9
9
 
10
10
  UserAgentSanitizer.sanitize_user_agent('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3')
11
- # => 'iPhone'
11
+ # => 'Apple iPhone'
12
12
 
13
13
  UserAgentSanitizer.sanitize_user_agent('Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; SAMSUNG GT-I9100/I9100BUKE5 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1')
14
14
  # => 'Samsung GT-I9100'
15
+
16
+ Since version 1.1.0, UserAgentSanitizer.user_agent is available:
17
+
18
+ ua = UserAgentSanitizer.user_agent('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3')
19
+ ua.brand
20
+ # => "Apple"
21
+ ua.model
22
+ # => "iPhone"
23
+ ua.to_s
24
+ # => "Apple iPhone"
15
25
 
16
26
  Installation
17
27
  ------------
data/Rakefile CHANGED
@@ -2,9 +2,6 @@ require 'rake'
2
2
  require 'rdoc/task'
3
3
  require "rake/gempackagetask"
4
4
 
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
5
  desc 'Generate documentation for the file_wrapper plugin.'
9
6
  Rake::RDocTask.new(:rdoc) do |rdoc|
10
7
  rdoc.rdoc_dir = 'rdoc'
@@ -1,62 +1,124 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module UserAgentSanitizer
2
3
  extend self
3
4
 
4
5
  BRANDS=["nokia", "samsung", "SonyEricsson", "BlackBerry", "htc", "sec", 'gt', 'iphone']
5
6
 
7
+ # Return a human-readable string representation of the user agent
6
8
  def sanitize_user_agent(string)
9
+ user_agent = user_agent(string)
10
+ return nil unless user_agent
11
+ user_agent.to_s
12
+ end
13
+
14
+ # Return the UserAgent wrapper for the user agent string
15
+ def user_agent(string)
7
16
  string = string.to_s
8
17
  return nil if string.empty?
9
- result = basic_user_agent_recognizer(string)
10
- result.gsub!(/^SAMSUNG/i, 'Samsung')
11
- result.gsub!(/^GT/i, 'Samsung GT')
12
- result.gsub!(/^Samsung GT\s+/i, 'Samsung GT-')
13
- result.gsub!(/^Desire(_\w+)/i, 'HTC Desire')
14
- result = "SonyEricsson #{$1}" if result =~ /^SonyEricsson(\w+)/i
15
- result.strip!
16
- result.squeeze!(" ")
17
- result
18
+ UserAgent.new(string)
18
19
  end
19
20
 
20
- protected
21
-
22
- def basic_user_agent_recognizer(string)
23
- case string
24
- when /(Mac OS X) (\d+_\d+_\d+)/
25
- return "#{$1} #{$2.gsub("_", ".")}"
26
- when /(LG|sagem)[\-\/](\w+)/i
27
- return "#{$1} #{$2}"
28
- when /(MSIE) (\d+(\.\d+)*)/
29
- return "#{$1} #{$2}"
30
- when /(Blackberry) ?(\d+)/i
31
- return "#{$1} #{$2}"
32
- when /(HTC)[_\/]([a-z0-9]+)?/i
33
- return [$1, $2].compact.join(" ")
34
- when /(Samsung)[\/\-]([a-z0-9]+)([\/\-]([a-z0-9]+))?/i
35
- return [$1, $2, $4].compact.join(" ")
36
- when /\((Linux; U; Android.*)\)/
37
- return $1.split(";").last.split("/").first.gsub(/build/i, "").strip
38
- when /(iPod)/
39
- return $1
40
- when /((#{BRANDS.join("|")}).*?)\//i
41
- result=$1
42
-
43
- result.gsub!(/build/i, "")
44
- result.gsub!(/-1/, "")
45
- result.gsub!(/-/, " ")
46
-
47
- if result=~/(.+?);/
48
- result = $1
21
+ class UserAgent
22
+ attr_accessor :brand, :model, :user_agent
23
+
24
+ def initialize(user_agent)
25
+ @user_agent = user_agent.dup
26
+ end
27
+
28
+ def brand
29
+ parse! unless parsed?
30
+ @brand
31
+ end
32
+
33
+ def model
34
+ parse! unless parsed?
35
+ @model
36
+ end
37
+
38
+ def to_s
39
+ "#{brand} #{model}".strip
40
+ end
41
+
42
+ protected
43
+
44
+ def parse!
45
+ return if @parsing
46
+ begin
47
+ @parsing = true
48
+ parse
49
+ ensure
50
+ @parsing = false
49
51
  end
52
+ end
50
53
 
51
- if result=~/(\D+)([A-Z]+\d+)/
52
- result="#{$1} #{$2}"
53
- elsif result=~/(\D+)(\d+)/
54
- result="#{$1} #{$2}"
54
+ def parsed?
55
+ @parsed
56
+ end
57
+
58
+ def parse
59
+ result = self.basic_user_agent_recognizer
60
+ if result
61
+ result.gsub!(/^SAMSUNG/i, 'Samsung')
62
+ result.gsub!(/^GT/i, 'Samsung GT')
63
+ result.gsub!(/^Samsung GT\s+/i, 'Samsung GT-')
64
+ result.gsub!(/^Desire(_\w+)/i, 'HTC Desire')
65
+ result.gsub!(/^iPhone/i, 'Apple iPhone')
66
+ result = "SonyEricsson #{$1}" if result =~ /^SonyEricsson(\w+)/i
67
+ result.strip!
68
+ result.squeeze!(" ")
69
+ brand, *model_ary = *result.split(" ")
70
+ @brand ||= brand
71
+ @model ||= model_ary.join(" ")
55
72
  end
73
+ self
74
+ end
56
75
 
57
- return result
58
- else
59
- return string
76
+ def basic_user_agent_recognizer
77
+ string = @user_agent.dup
78
+ case string
79
+ when /(Mac OS X) (\d+_\d+_\d+)/
80
+ @brand = 'Apple'
81
+ @model = "#{$1} #{$2.gsub("_", ".")}"
82
+ return nil
83
+ when /(LG|sagem)[\-\/](\w+)/i
84
+ return "#{$1} #{$2}"
85
+ when /(MSIE) (\d+(\.\d+)*)/
86
+ @brand = 'Microsoft'
87
+ @model = "Internet Explorer #{$2}"
88
+ return nil
89
+ when /(Blackberry) ?(\d+)/i
90
+ return "#{$1} #{$2}"
91
+ when /(HTC)[_\/]([a-z0-9]+)?/i
92
+ return [$1, $2].compact.join(" ")
93
+ when /(Samsung)[\/\-]([a-z0-9]+)([\/\-]([a-z0-9]+))?/i
94
+ return ['Samsung', $2, $4].compact.join(" ")
95
+ when /\((Linux; U; Android.*)\)/
96
+ return $1.split(";").last.split("/").first.gsub(/build/i, "").strip
97
+ when /(iPod)/
98
+ @brand = 'Apple'
99
+ @model = 'iPod'
100
+ return nil
101
+ when /((#{BRANDS.join("|")}).*?)\//i
102
+ result=$1
103
+
104
+ result.gsub!(/build/i, "")
105
+ result.gsub!(/-1/, "")
106
+ result.gsub!(/-/, " ")
107
+
108
+ if result=~/(.+?);/
109
+ result = $1
110
+ end
111
+
112
+ if result=~/(\D+)([A-Z]+\d+)/
113
+ result="#{$1} #{$2}"
114
+ elsif result=~/(\D+)(\d+)/
115
+ result="#{$1} #{$2}"
116
+ end
117
+
118
+ return result
119
+ else
120
+ return string
121
+ end
60
122
  end
61
123
  end
62
124
  end
@@ -3,50 +3,63 @@ require 'spec_helper'
3
3
  require 'user_agent_sanitizer'
4
4
 
5
5
  describe UserAgentSanitizer do
6
+ DEVICES = {
7
+ 'BlackBerry8520/4.6.1.296 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/150' => ['BlackBerry', '8520'],
8
+ 'BlackBerry8900/4.6.1.199 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/302' => ['BlackBerry', '8900'],
9
+ 'LG-GD510/V100 Teleca/WAP2.0 Profile/MIDP-2.1 Configuration/CLDC-1.1' => ['LG', 'GD510'],
10
+ 'LG/KU990/v10a Browser/Obigo-Q05A/3.6 MMS/LG-MMS-V1.0/1.2 Java/ASVM/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' => ['LG','KU990'],
11
+ 'Mozilla/5.0 (Linux; U; Android 2.1-update1; nl-nl; Desire_A8181 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' => ['HTC','Desire'],
12
+ 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB0.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)' => ['Microsoft','Internet Explorer 7.0'],
13
+ 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; nl) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+' => ['BlackBerry','9800'],
14
+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3' => ['Apple','iPhone'],
15
+ 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5' => ['Apple','iPhone'],
16
+ 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; nl-nl) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419.3' => ['Apple','iPhone'],
17
+ 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5' => ['Apple','iPod'],
18
+ 'Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8500/S8500XXJEC; U; Bada/1.0; nl-nl) AppleWebKit/533.1 (KHTML, like Gecko) Dolfin/2.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B' => ['Samsung','GT-S8500'],
19
+ 'HTC_Touch2_T3333 Opera/9.50 (Windows NT 5.1; U; nl)' => ['HTC','Touch2'],
20
+ 'Mozilla/5.0 (Linux; U; Android 1.5; en-gb; HTC Magic Build/CRB17) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['HTC','Magic'],
21
+ 'Mozilla/5.0 (Linux; U; Android 1.5; nl-nl; GT-I5700 Build/CUPCAKE) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['Samsung','GT-I5700'],
22
+ 'Mozilla/5.0 (Linux; U; Android 2.1; nl-nl; HTC Legend Build/ERD79) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' => ['HTC','Legend'],
23
+ 'Mozilla/5.0 (Linux; U; Android 2.2.1; es-es; Vodafone 858 Build/Vodafone858C02B617) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['Vodafone','858'],
24
+ 'Mozilla/5.0 (Linux; U; Android 2.2; es-es; Light Pro Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['Light','Pro'],
25
+ 'Mozilla/5.0 (Linux; U; Android 2.2; nl-nl; HTC_DesireZ_A7272 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['HTC','DesireZ'],
26
+ 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; GT-I9100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['Samsung','GT-I9100'],
27
+ 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; HTC/DesireS/1.32.161.2 Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['HTC','DesireS'],
28
+ 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; SAMSUNG GT-I9100/I9100BUKE5 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['Samsung','GT-I9100'],
29
+ 'Mozilla/5.0 (Linux; U; Android 2.3.5; es-es; ZTE Skate Build/V1.0.0B03) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['ZTE','Skate'],
30
+ 'Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus One Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['Nexus','One'],
31
+ 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; nl-nl) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1' => ['Apple','Mac OS X 10.5.5'],
32
+ 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10' => ['Apple','Mac OS X 10.6.2'],
33
+ 'Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE90-1/07.24.0.3; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413' => ['Nokia','E90'],
34
+ 'Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1/110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413' => ['Nokia','E75'],
35
+ 'Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Samsung/I8910; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 Safari/525' => ['Samsung','I8910'],
36
+ 'Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/24.871; U; pt) Presto/2.5.25 Version/10.54' => ['BlackBerry', ''],
37
+ 'SAGEM-my411C/1.0/ MIDP-2.0 Configuration/CLDC-1.1 Browser/UP.Browser/7.2.6.c.1.386 (GUI)' => ['SAGEM','my411C'],
38
+ 'SAMSUNG-GT-C3510/C3510XXIL4 NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1' => ['Samsung','GT-C3510'],
39
+ 'SAMSUNG-SGH-L600/L600ASGI3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => ['Samsung','SGH L600'],
40
+ 'SEC-SGHM620/1.0 Openwave/6.2.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => ['SEC','SGH M620'],
41
+ 'SonyEricssonW995/R1FA Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1 JavaPlatform/JP-8.4.3' => ['SonyEricsson','W995'],
42
+ 'Mozilla/5.0 (Linux; U; Android 1.6; nl-nl; SonyEricssonX10i Build/R1FA016) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['SonyEricsson','X10i'],
43
+ }
6
44
  describe "sanitize_user_agent" do
7
- {
8
- 'BlackBerry8520/4.6.1.296 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/150' => 'BlackBerry 8520',
9
- 'BlackBerry8900/4.6.1.199 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/302' => 'BlackBerry 8900',
10
- 'LG-GD510/V100 Teleca/WAP2.0 Profile/MIDP-2.1 Configuration/CLDC-1.1' => 'LG GD510',
11
- 'LG/KU990/v10a Browser/Obigo-Q05A/3.6 MMS/LG-MMS-V1.0/1.2 Java/ASVM/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' => 'LG KU990',
12
- 'Mozilla/5.0 (Linux; U; Android 2.1-update1; nl-nl; Desire_A8181 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' => 'HTC Desire',
13
- 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB0.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)' => 'MSIE 7.0',
14
- 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; nl) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+' => 'BlackBerry 9800',
15
- 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3' => 'iPhone',
16
- 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5' => 'iPhone',
17
- 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; nl-nl) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419.3' => 'iPhone',
18
- 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5' => 'iPod',
19
- 'Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8500/S8500XXJEC; U; Bada/1.0; nl-nl) AppleWebKit/533.1 (KHTML, like Gecko) Dolfin/2.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B' => 'Samsung GT-S8500',
20
- 'HTC_Touch2_T3333 Opera/9.50 (Windows NT 5.1; U; nl)' => 'HTC Touch2',
21
- 'Mozilla/5.0 (Linux; U; Android 1.5; en-gb; HTC Magic Build/CRB17) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => 'HTC Magic',
22
- 'Mozilla/5.0 (Linux; U; Android 1.5; nl-nl; GT-I5700 Build/CUPCAKE) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => 'Samsung GT-I5700',
23
- 'Mozilla/5.0 (Linux; U; Android 2.1; nl-nl; HTC Legend Build/ERD79) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' => 'HTC Legend',
24
- 'Mozilla/5.0 (Linux; U; Android 2.2.1; es-es; Vodafone 858 Build/Vodafone858C02B617) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Vodafone 858',
25
- 'Mozilla/5.0 (Linux; U; Android 2.2; es-es; Light Pro Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Light Pro',
26
- 'Mozilla/5.0 (Linux; U; Android 2.2; nl-nl; HTC_DesireZ_A7272 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'HTC DesireZ',
27
- 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; GT-I9100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Samsung GT-I9100',
28
- 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; HTC/DesireS/1.32.161.2 Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'HTC DesireS',
29
- 'Mozilla/5.0 (Linux; U; Android 2.3.3; nl-nl; SAMSUNG GT-I9100/I9100BUKE5 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Samsung GT-I9100',
30
- 'Mozilla/5.0 (Linux; U; Android 2.3.5; es-es; ZTE Skate Build/V1.0.0B03) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'ZTE Skate',
31
- 'Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus One Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => 'Nexus One',
32
- 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; nl-nl) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1' => 'Mac OS X 10.5.5',
33
- 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10' => 'Mac OS X 10.6.2',
34
- 'Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE90-1/07.24.0.3; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413' => 'Nokia E90',
35
- 'Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1/110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413' => 'Nokia E75',
36
- 'Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Samsung/I8910; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 Safari/525' => 'Samsung I8910',
37
- 'Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/24.871; U; pt) Presto/2.5.25 Version/10.54' => 'BlackBerry',
38
- 'SAGEM-my411C/1.0/ MIDP-2.0 Configuration/CLDC-1.1 Browser/UP.Browser/7.2.6.c.1.386 (GUI)' => 'SAGEM my411C',
39
- 'SAMSUNG-GT-C3510/C3510XXIL4 NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1' => 'Samsung GT-C3510',
40
- 'SAMSUNG-SGH-L600/L600ASGI3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => 'Samsung SGH L600',
41
- 'SEC-SGHM620/1.0 Openwave/6.2.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => 'SEC SGH M620',
42
- 'SonyEricssonW995/R1FA Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1 JavaPlatform/JP-8.4.3' => 'SonyEricsson W995',
43
- 'Mozilla/5.0 (Linux; U; Android 1.6; nl-nl; SonyEricssonX10i Build/R1FA016) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => 'SonyEricsson X10i',
44
- '' => nil,
45
- nil => nil,
46
- }.each do |user_agent, device_name|
45
+ DEVICES.each do |user_agent, brand_model|
46
+ device_name = brand_model.join(" ").strip
47
47
  it "should return #{device_name.inspect} for #{user_agent.inspect}" do
48
48
  UserAgentSanitizer.sanitize_user_agent(user_agent).should == device_name
49
49
  end
50
50
  end
51
51
  end
52
+
53
+ describe "user_agent" do
54
+ DEVICES.each do |user_agent, brand_model|
55
+ brand, model = *brand_model
56
+ it "should return brand #{brand.inspect} and model #{model.inspect} for #{user_agent.inspect}" do
57
+ ua=UserAgentSanitizer.user_agent(user_agent)
58
+ ua.to_s.should == brand_model.join(" ").strip
59
+ ua.brand.should == brand
60
+ ua.model.should == model
61
+ ua.user_agent.should == user_agent
62
+ end
63
+ end
64
+ end
52
65
  end
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.name = 'user_agent_sanitizer'
4
4
  s.summary = "Browser user agent sanitizer"
5
5
  s.description = "Browser user agent sanitizer, with a focus on sanitizing mobile phone user agents to brand + model number"
6
- s.version = '1.0.0'
6
+ s.version = '1.1.0'
7
7
  s.date = '2002-06-15'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Wes Oldenbeuving"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_agent_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: