phony 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -194,7 +194,9 @@ country '354', none >> split(3,4) # Iceland
194
194
  country '355', fixed(2) >> split(3,2,2) # Albania
195
195
  country '356', fixed(2) >> split(3,2,2) # Malta
196
196
  country '357', fixed(2) >> split(3,2,2) # Cyprus
197
- country '358', fixed(2) >> split(3,2,2) # Finland
197
+ country '358', match(/^([6-8]00)\d+$/) >> split(3,3) | # Finland
198
+ match(/^(4\d|50)\d+$/) >> split(3,2,2) |
199
+ one_of('2','3','5','6','8','9', :max_length => 2) >> split(3,3)
198
200
  country '359', fixed(2) >> split(3,2,2) # Bulgaria
199
201
 
200
202
  country '370', fixed(2) >> split(3,2,2) # Lithuania
@@ -0,0 +1,182 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe 'country descriptions' do
6
+
7
+ describe "splitting" do
8
+ it 'handles afghan numbers' do
9
+ Phony.split('93201234567').should == ['93', '20', '1234567'] # Kabul
10
+ end
11
+ it 'handles algerian numbers' do
12
+ Phony.split('213211231234').should == ['213', '21', '123', '1234'] # Algiers
13
+ Phony.split('213331231234').should == ['213', '33', '123', '1234'] # Batna
14
+ end
15
+ it "handles austrian numbers" do
16
+ Phony.split('43198110').should == ['43', '1', '98110'] # Vienna
17
+ Phony.split('4366914093902').should == ['43', '669', '14093902'] # Mobile
18
+ Phony.split('433161234567891').should == ['43', '316', '1234567891'] # Graz
19
+ Phony.split('432164123456789').should == ['43', '2164', '123456789'] # Rohrau
20
+ end
21
+ it 'handles belgian numbers' do
22
+ Phony.split('3235551212').should == ['32', '3', '555', '1212'] # Antwerpen
23
+ Phony.split('32505551212').should == ['32', '50', '555', '1212'] # Brugge
24
+ Phony.split('3225551212').should == ['32', '2', '555', '1212'] # Brussels
25
+ Phony.split('3295551914').should == ['32', '9', '555', '1914'] # Gent
26
+ Phony.split('3245551414').should == ['32', '4', '555', '1414'] # Liège
27
+ Phony.split('32475279584').should == ['32', '475', '279584'] # mobile
28
+ end
29
+ it 'handles brazilian numbers' do
30
+ Phony.split('551112341234').should == ['55', '11', '1234', '1234']
31
+ end
32
+ it 'handles chilean numbers' do
33
+ Phony.split('5621234567').should == ['56', '2', '1234567'] # Santiago
34
+ Phony.split('5675123456').should == ['56', '75', '123456'] # Curico
35
+ Phony.split('56912345678').should == ['56', '9', '12345678'] # mobile
36
+ end
37
+ it 'handles chinese numbers' do
38
+ Phony.split('862112345678').should == ['86', '21', '1234', '5678'] # Shanghai
39
+ Phony.split('8675582193447').should == ['86', '755', '8219', '3447'] # Shenzhen
40
+ end
41
+ it 'handles cuban numbers' do
42
+ Phony.split('5351231234').should == ['53', '5123', '1234'] # Mobile
43
+ Phony.split('5371234567').should == ['53', '7', '1234567'] # Havana
44
+ Phony.split('5342123456').should == ['53', '42', '123456'] # Villa Clara
45
+ end
46
+ it 'handles danish numbers' do
47
+ Phony.split('4532121212').should == ['45', '32', '12', '12', '12']
48
+ end
49
+ it 'handles dutch numbers' do
50
+ Phony.split('31612345678').should == ['31', '6', '12345678'] # mobile
51
+ Phony.split('31201234567').should == ['31', '20', '1234567']
52
+ Phony.split('31222123456').should == ['31', '222', '123456']
53
+ end
54
+ it "handles egyptian numbers" do
55
+ Phony.split('20212345678').should == ['20', '2', '12345678']
56
+ Phony.split('20921234567').should == ['20', '92', '1234567']
57
+ Phony.split('20951234567').should == ['20', '95', '1234567']
58
+ end
59
+ it 'handles finnish numbers' do
60
+ Phony.split('3589123123').should == ['358', '9', '123', '123'] # Helsinki
61
+ Phony.split('3581912312').should == ['358', '19', '123', '12'] # Nylandia
62
+ Phony.split('3585012312').should == ['358', '50', '123', '12'] # Mobile
63
+ Phony.split('358600123').should == ['358', '600', '123'] # Service
64
+ end
65
+ it "handles french numbers" do
66
+ Phony.split('33112345678').should == ['33', '1', '12','34','56','78']
67
+ end
68
+ it "handles german numbers" do
69
+ Phony.split('4930123456').should == ['49', '30', '123', '456']
70
+ Phony.split('4976112345').should == ['49', '761', '123', '45']
71
+ Phony.split('492041123456').should == ['49', '2041', '123', '456']
72
+ Phony.split('493434112345').should == ['49', '34341', '123', '45'] # Geithain
73
+ end
74
+ it "handles greek numbers" do
75
+ Phony.split('3021123456').should == ['30', '21', '123456']
76
+ Phony.split('3025941234').should == ['30', '2594', '1234']
77
+ Phony.split('3022631234').should == ['30', '2263', '1234']
78
+ end
79
+ it "handles hungarian numbers" do
80
+ Phony.split('3612345678').should == ['36', '1', '234', '5678']
81
+ end
82
+ it "handles icelandic numbers" do
83
+ Phony.split('354112').should == ['354', '112'] # Emergency TODO
84
+ Phony.split('3544211234').should == ['354', '421', '1234'] # Keflavík
85
+ Phony.split('3544621234').should == ['354', '462', '1234'] # Akureyri
86
+ Phony.split('3545511234').should == ['354', '551', '1234'] # Reykjavík
87
+ end
88
+ it "handles italian numbers" do
89
+ Phony.split('3934869528').should == ['39', '3486', '952', '8'] # Mobile
90
+ Phony.split('39068546705').should == ['39', '06', '854', '6705'] # Roma
91
+ Phony.split('390909709511').should == ['39', '090', '970', '9511'] # Barcellona
92
+ end
93
+ it 'handles malay numbers' do
94
+ Phony.split('6082123456').should == ['60', '82', '123456'] # Kuching
95
+ Phony.split('60312345678').should == ['60', '3', '12345678'] # Kuala Lumpur
96
+ Phony.split('60212345678').should == ['60', '2', '12345678'] # Singapore
97
+ end
98
+ it 'handles mexican numbers' do
99
+ Phony.split('525512121212').should == ['52', '55', '12', '12', '12', '12'] # Mexico City
100
+ Phony.split('526641231212').should == ['52', '664', '123', '12', '12'] # Tijuana
101
+ end
102
+ it 'handles norwegian numbers' do
103
+ Phony.split('4721234567').should == ['47','21','23','45','67']
104
+ Phony.split('4731234567').should == ['47','31','23','45','67']
105
+ Phony.split('4741234567').should == ['47','412','34','567']
106
+ Phony.split('4751234567').should == ['47','51','23','45','67']
107
+ Phony.split('4761234567').should == ['47','61','23','45','67']
108
+ Phony.split('4771234567').should == ['47','71','23','45','67']
109
+ Phony.split('4781234567').should == ['47','812','34','567']
110
+ Phony.split('4791234567').should == ['47','912','34','567']
111
+ end
112
+ it 'handles peruvian numbers' do
113
+ Phony.split('51112341234').should == ['51', '1', '1234', '1234'] # Lima
114
+ Phony.split('51912341234').should == ['51', '9', '1234', '1234'] # mobile
115
+ Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
116
+ end
117
+ it "handles polish numbers" do
118
+ Phony.split('48123123123').should == ['48', '123', '123', '123']
119
+ end
120
+ it 'handles portuguese numbers' do
121
+ Phony.split('351211231234').should == ['351', '21', '123', '1234'] # Lisboa
122
+ Phony.split('351241123123').should == ['351', '241', '123', '123'] # Abrantes
123
+ Phony.split('351931231234').should == ['351', '93', '123', '1234'] # mobile
124
+ end
125
+ it 'handles romanian numbers' do
126
+ Phony.split('40211231234').should == ['40', '21', '123', '1234'] # Bucureşti
127
+ Phony.split('40721231234').should == ['40', '72', '123', '1234'] # mobile
128
+ Phony.split('40249123123').should == ['40', '249', '123', '123'] # Olt
129
+ end
130
+ it 'handles russian numbers' do
131
+ Phony.split('78122345678').should == ['7', '812', '234', '56', '78']
132
+ end
133
+ it 'handles south korean numbers' do
134
+ Phony.split('82212345678').should == ['82', '2', '1234', '5678'] # Seoul
135
+ Phony.split('825112345678').should == ['82', '51', '1234', '5678'] # Busan
136
+ Phony.split('821027975588').should == ['82', '10', '2797', '5588'] # mobile
137
+ end
138
+ it 'handles tunisian numbers' do
139
+ Phony.split('21611231234').should == ['216', '1', '123', '1234'] # Ariana
140
+ Phony.split('21621231234').should == ['216', '2', '123', '1234'] # Bizerte
141
+ end
142
+ it "handles swedish numbers" do
143
+ Phony.split('46812345678').should == ['46', '8', '12345678'] # Stockholm
144
+ Phony.split('46111234567').should == ['46', '11', '1234567']
145
+ Phony.split('46125123456').should == ['46', '125', '123456']
146
+ end
147
+ it "handles swiss numbers" do
148
+ Phony.split('41443643532').should == ['41', '44', '364', '35', '32']
149
+ end
150
+ it 'handles turkish numbers' do
151
+ Phony.split('903121234567').should == ['90', '312', '123', '4567'] # Ankara
152
+ end
153
+ it 'handles UK numbers' do
154
+ Phony.split('442045671113').should == ['44', '20', '4567', '1113'] # London
155
+ Phony.split('442076229901').should == ['44', '20', '7622', '9901'] # Cardiff
156
+ Phony.split('441136770011').should == ['44', '113', '677', '0011'] # Leeds
157
+ Phony.split('441382229845').should == ['44', '1382', '229845'] # Dundee
158
+ Phony.split('44120499532').should == ['44', '1204', '99532'] # Bolten
159
+ Phony.split('441539618756').should == ['44', '15396', '18756'] # Sedbergh
160
+ Phony.split('447780605207').should == ['44', '7780', '605207'] # Mobile
161
+ Phony.split('447480605207').should == ['44', '7480', '605207'] # Mobile
162
+ Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Service, regression
163
+ end
164
+ it "handles US numbers" do
165
+ Phony.split('15551115511').should == ['1', '555', '111', '5511']
166
+ end
167
+ it "handles venezuelan numbers" do
168
+ Phony.split('582121234567').should == ["58", "212", "1234567"]
169
+ end
170
+ it "handles new zealand numbers" do
171
+ Phony.split('6491234567').should == ['64', '9', '123', '4567']
172
+ end
173
+
174
+ it "handles french service numbers" do
175
+ Phony.split('33812345678').should == ['33', '8', '12','34','56','78']
176
+ end
177
+ it "handles swiss service numbers" do
178
+ Phony.split('41800334455').should == ['41', '800', '334', '455']
179
+ end
180
+ end
181
+
182
+ end
@@ -4,175 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  describe Phony do
6
6
 
7
- describe "split" do
8
- it 'handles afghan numbers' do
9
- Phony.split('93201234567').should == ['93', '20', '1234567'] # Kabul
10
- end
11
- it 'handles algerian numbers' do
12
- Phony.split('213211231234').should == ['213', '21', '123', '1234'] # Algiers
13
- Phony.split('213331231234').should == ['213', '33', '123', '1234'] # Batna
14
- end
15
- it "handles austrian numbers" do
16
- Phony.split('43198110').should == ['43', '1', '98110'] # Vienna
17
- Phony.split('4366914093902').should == ['43', '669', '14093902'] # Mobile
18
- Phony.split('433161234567891').should == ['43', '316', '1234567891'] # Graz
19
- Phony.split('432164123456789').should == ['43', '2164', '123456789'] # Rohrau
20
- end
21
- it 'handles belgian numbers' do
22
- Phony.split('3235551212').should == ['32', '3', '555', '1212'] # Antwerpen
23
- Phony.split('32505551212').should == ['32', '50', '555', '1212'] # Brugge
24
- Phony.split('3225551212').should == ['32', '2', '555', '1212'] # Brussels
25
- Phony.split('3295551914').should == ['32', '9', '555', '1914'] # Gent
26
- Phony.split('3245551414').should == ['32', '4', '555', '1414'] # Liège
27
- Phony.split('32475279584').should == ['32', '475', '279584'] # mobile
28
- end
29
- it 'handles brazilian numbers' do
30
- Phony.split('551112341234').should == ['55', '11', '1234', '1234']
31
- end
32
- it 'handles chilean numbers' do
33
- Phony.split('5621234567').should == ['56', '2', '1234567'] # Santiago
34
- Phony.split('5675123456').should == ['56', '75', '123456'] # Curico
35
- Phony.split('56912345678').should == ['56', '9', '12345678'] # mobile
36
- end
37
- it 'handles chinese numbers' do
38
- Phony.split('862112345678').should == ['86', '21', '1234', '5678'] # Shanghai
39
- Phony.split('8675582193447').should == ['86', '755', '8219', '3447'] # Shenzhen
40
- end
41
- it 'handles cuban numbers' do
42
- Phony.split('5351231234').should == ['53', '5123', '1234'] # Mobile
43
- Phony.split('5371234567').should == ['53', '7', '1234567'] # Havana
44
- Phony.split('5342123456').should == ['53', '42', '123456'] # Villa Clara
45
- end
46
- it 'handles danish numbers' do
47
- Phony.split('4532121212').should == ['45', '32', '12', '12', '12']
48
- end
49
- it 'handles dutch numbers' do
50
- Phony.split('31612345678').should == ['31', '6', '12345678'] # mobile
51
- Phony.split('31201234567').should == ['31', '20', '1234567']
52
- Phony.split('31222123456').should == ['31', '222', '123456']
53
- end
54
- it "handles egyptian numbers" do
55
- Phony.split('20212345678').should == ['20', '2', '12345678']
56
- Phony.split('20921234567').should == ['20', '92', '1234567']
57
- Phony.split('20951234567').should == ['20', '95', '1234567']
58
- end
59
- it "handles french numbers" do
60
- Phony.split('33112345678').should == ['33', '1', '12','34','56','78']
61
- end
62
- it "handles german numbers" do
63
- Phony.split('4930123456').should == ['49', '30', '123', '456']
64
- Phony.split('4976112345').should == ['49', '761', '123', '45']
65
- Phony.split('492041123456').should == ['49', '2041', '123', '456']
66
- Phony.split('493434112345').should == ['49', '34341', '123', '45'] # Geithain
67
- end
68
- it "should handle greek numbers" do
69
- Phony.split('3021123456').should == ['30', '21', '123456']
70
- Phony.split('3025941234').should == ['30', '2594', '1234']
71
- Phony.split('3022631234').should == ['30', '2263', '1234']
72
- end
73
- it "should handle hungarian numbers" do
74
- Phony.split('3612345678').should == ['36', '1', '234', '5678']
75
- end
76
- it "should handle icelandic numbers" do
77
- Phony.split('354112').should == ['354', '112'] # Emergency TODO
78
- Phony.split('3544211234').should == ['354', '421', '1234'] # Keflavík
79
- Phony.split('3544621234').should == ['354', '462', '1234'] # Akureyri
80
- Phony.split('3545511234').should == ['354', '551', '1234'] # Reykjavík
81
- end
82
- it "should handle italian numbers" do
83
- Phony.split('3934869528').should == ['39', '3486', '952', '8'] # Mobile
84
- Phony.split('39068546705').should == ['39', '06', '854', '6705'] # Roma
85
- Phony.split('390909709511').should == ['39', '090', '970', '9511'] # Barcellona
86
- end
87
- it 'handles malay numbers' do
88
- Phony.split('6082123456').should == ['60', '82', '123456'] # Kuching
89
- Phony.split('60312345678').should == ['60', '3', '12345678'] # Kuala Lumpur
90
- Phony.split('60212345678').should == ['60', '2', '12345678'] # Singapore
91
- end
92
- it 'handles mexican numbers' do
93
- Phony.split('525512121212').should == ['52', '55', '12', '12', '12', '12'] # Mexico City
94
- Phony.split('526641231212').should == ['52', '664', '123', '12', '12'] # Tijuana
95
- end
96
- it 'handles norwegian numbers' do
97
- Phony.split('4721234567').should == ['47','21','23','45','67']
98
- Phony.split('4731234567').should == ['47','31','23','45','67']
99
- Phony.split('4741234567').should == ['47','412','34','567']
100
- Phony.split('4751234567').should == ['47','51','23','45','67']
101
- Phony.split('4761234567').should == ['47','61','23','45','67']
102
- Phony.split('4771234567').should == ['47','71','23','45','67']
103
- Phony.split('4781234567').should == ['47','812','34','567']
104
- Phony.split('4791234567').should == ['47','912','34','567']
105
- end
106
- it 'handles peruvian numbers' do
107
- Phony.split('51112341234').should == ['51', '1', '1234', '1234'] # Lima
108
- Phony.split('51912341234').should == ['51', '9', '1234', '1234'] # mobile
109
- Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
110
- end
111
- it "handles polish numbers" do
112
- Phony.split('48123123123').should == ['48', '123', '123', '123']
113
- end
114
- it 'handles portuguese numbers' do
115
- Phony.split('351211231234').should == ['351', '21', '123', '1234'] # Lisboa
116
- Phony.split('351241123123').should == ['351', '241', '123', '123'] # Abrantes
117
- Phony.split('351931231234').should == ['351', '93', '123', '1234'] # mobile
118
- end
119
- it 'handles romanian numbers' do
120
- Phony.split('40211231234').should == ['40', '21', '123', '1234'] # Bucureşti
121
- Phony.split('40721231234').should == ['40', '72', '123', '1234'] # mobile
122
- Phony.split('40249123123').should == ['40', '249', '123', '123'] # Olt
123
- end
124
- it 'handles russian numbers' do
125
- Phony.split('78122345678').should == ['7', '812', '234', '56', '78']
126
- end
127
- it 'handles south korean numbers' do
128
- Phony.split('82212345678').should == ['82', '2', '1234', '5678'] # Seoul
129
- Phony.split('825112345678').should == ['82', '51', '1234', '5678'] # Busan
130
- Phony.split('821027975588').should == ['82', '10', '2797', '5588'] # mobile
131
- end
132
- it 'handles tunisian numbers' do
133
- Phony.split('21611231234').should == ['216', '1', '123', '1234'] # Ariana
134
- Phony.split('21621231234').should == ['216', '2', '123', '1234'] # Bizerte
135
- end
136
- it "should handle swedish numbers" do
137
- Phony.split('46812345678').should == ['46', '8', '12345678'] # Stockholm
138
- Phony.split('46111234567').should == ['46', '11', '1234567']
139
- Phony.split('46125123456').should == ['46', '125', '123456']
140
- end
141
- it "should handle swiss numbers" do
142
- Phony.split('41443643532').should == ['41', '44', '364', '35', '32']
143
- end
144
- it 'handles turkish numbers' do
145
- Phony.split('903121234567').should == ['90', '312', '123', '4567'] # Ankara
146
- end
147
- it 'handles UK numbers' do
148
- Phony.split('442045671113').should == ['44', '20', '4567', '1113'] # London
149
- Phony.split('442076229901').should == ['44', '20', '7622', '9901'] # Cardiff
150
- Phony.split('441136770011').should == ['44', '113', '677', '0011'] # Leeds
151
- Phony.split('441382229845').should == ['44', '1382', '229845'] # Dundee
152
- Phony.split('44120499532').should == ['44', '1204', '99532'] # Bolten
153
- Phony.split('441539618756').should == ['44', '15396', '18756'] # Sedbergh
154
- Phony.split('447780605207').should == ['44', '7780', '605207'] # Mobile
155
- Phony.split('447480605207').should == ['44', '7480', '605207'] # Mobile
156
- Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Service, regression
157
- end
158
- it "handles US numbers" do
159
- Phony.split('15551115511').should == ['1', '555', '111', '5511']
160
- end
161
- it "should handle venezuelan numbers" do
162
- Phony.split('582121234567').should == ["58", "212", "1234567"]
163
- end
164
- it "should handle new zealand numbers" do
165
- Phony.split('6491234567').should == ['64', '9', '123', '4567']
166
- end
167
-
168
- it "should handle french service numbers" do
169
- Phony.split('33812345678').should == ['33', '8', '12','34','56','78']
170
- end
171
- it "should handle swiss service numbers" do
172
- Phony.split('41800334455').should == ['41', '800', '334', '455']
173
- end
174
- end
175
-
176
7
  describe "normalize" do
177
8
  describe "some examples" do
178
9
  it "should normalize an already normalized number" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.0
5
+ version: 1.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-26 00:00:00 +01:00
13
+ date: 2011-02-27 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -54,6 +54,7 @@ files:
54
54
  - lib/phony/vanity.rb
55
55
  - lib/phony.rb
56
56
  - README.textile
57
+ - spec/lib/countries_spec.rb
57
58
  - spec/lib/phony/countries/germany_spec.rb
58
59
  - spec/lib/phony/countries/hungary_spec.rb
59
60
  - spec/lib/phony/country_codes_spec.rb
@@ -96,6 +97,7 @@ signing_key:
96
97
  specification_version: 3
97
98
  summary: Fast international phone number (E164 standard) normalizing, splitting and formatting.
98
99
  test_files:
100
+ - spec/lib/countries_spec.rb
99
101
  - spec/lib/phony/countries/germany_spec.rb
100
102
  - spec/lib/phony/countries/hungary_spec.rb
101
103
  - spec/lib/phony/country_codes_spec.rb