phony 1.7.10 → 1.7.11

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.
@@ -118,7 +118,11 @@ Phony.define do
118
118
  one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
119
119
  one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
120
120
  one_of(%w(929 995344 9971 99744 9976 997)) >> split(2, 2, 2) | # South Osetia
121
- match(/([67]\d{2})/) >> split(2, 2, 2) | # Kazakhstan: (600..799)
122
- one_of(%w(840 940)) >> split(2,2,2) # Abhasia
121
+
122
+ # The two following lines have been replaced by fixed(3).
123
+ #
124
+ # match(/([67]\d{2})/) >> split(2, 2, 2) | # Kazakhstan: (600..799)
125
+ # one_of(%w(840 940)) >> split(2,2,2) # Abhasia
126
+
123
127
  fixed(3) >> split(2,2,2)
124
128
  end
@@ -1,34 +1,40 @@
1
- # The United Kingdom uses a variable-length ndc code,
2
- # thus we use a separate file to not let all_other.rb explode.
1
+ # The United Kingdom uses a variable-length NDC code,
2
+ # thus we use a separate file to not let countries.rb explode.
3
3
  #
4
- # Note: The United Kingdom uses a variable ndc format from length 2 to 5.
4
+ # Note: The United Kingdom uses a variable NDC format from length 2 to 5.
5
5
  #
6
6
  # The UK is special in formatting in that it uses:
7
- # a 4-4 formatting rule with area codes that are 2 digits long,
8
- # a 3-4 formatting rule with area codes that are 3 digits long,
9
- # a 6 or 5 formatting rule with area codes that are 4 digits long, and
10
- # a 5 or 4 formatting rule with area codes that are 5 digits long.
11
- #
12
- # To reflect this different formatting, we need to install all handlers in a row.
13
- # First, the area codes of length 2, without a fallback length (since this
14
- # captures all), but with a nil fallback length.
15
- #
16
- # TODO Implement and use length-based splitter.
7
+ # a 2-4-4 formatting rule with area codes that are 2 digits long,
8
+ # a 3-3-4 or 3-6 formatting rule with area codes that are 3 digits long,
9
+ # a 4-6 or 4-5 formatting rule with area codes that are 4 digits long, and
10
+ # a 5-5 or 5-4 formatting rule with area codes that are 5 digits long.
11
+ # There can be a mix of number lengths within a single area code.
17
12
  #
18
13
 
19
14
  two_digit_ndc = [
15
+ # Geographic [2+8].
16
+ #
20
17
  '20', # London
21
18
  '23', # Southampton, Portsmith
22
19
  '24', # Coventry
23
20
  '28', # Northern Ireland
24
21
  '29', # Cardiff
22
+
23
+ # Non-geographic [2+8].
24
+ #
25
25
  '55', # Corporate
26
26
  '56', # LIECS/VoIP
27
27
  '70', # Personal numbers
28
28
  ]
29
29
 
30
+ # three_digit_ndc_with_nine_digits
31
+ # Non-geographic [3+6].
32
+ #
33
+ # '500', # Freephone (9 digits) handled in specific rule, see below.
34
+ # '800', # Freephone (9 digits) handled in specific rule, see below.
35
+
30
36
  three_digit_ndc = [
31
- # Geographic.
37
+ # Geographic [3+7].
32
38
  #
33
39
  '113', # Leeds
34
40
  '114', # Sheffield
@@ -41,15 +47,14 @@ three_digit_ndc = [
41
47
  '141', # Glasgow
42
48
  '151', # Liverpool
43
49
  '161', # Manchester
44
- '171', # Used for inner London until 2000
45
- '181', # Used for outer London until 2000
46
50
  '191', # Tyne and Wear/County Durham
47
51
 
48
- # Services.
52
+ # Services [3+7].
49
53
  #
50
54
  '300', # Non-geographic charged at same rate as 01
51
55
  '301',
52
56
  '303',
57
+ '306',
53
58
  '308',
54
59
  '309',
55
60
  '330',
@@ -66,20 +71,20 @@ three_digit_ndc = [
66
71
  '372',
67
72
  '373',
68
73
 
69
- '800', # Freephone (9 or 10 digits)
74
+ '800', # Freephone (10 digits) # 9 digits handled in specific rule, see below.
70
75
  '808', # Freephone (10 digits)
71
76
 
72
- '842', # Business rate
77
+ '842', # Business rate [3+7].
73
78
  '843',
74
79
  '844',
75
80
  '845',
76
81
  '870',
77
82
 
78
- '871', # Premium rate
83
+ '871', # Premium rate [3+7].
79
84
  '872',
80
85
  '873',
81
86
 
82
- '900', # Premium rate content services
87
+ '900', # Premium rate content services [3+7].
83
88
  '901',
84
89
  '902',
85
90
  '903',
@@ -88,18 +93,42 @@ three_digit_ndc = [
88
93
  '906',
89
94
  '907',
90
95
 
91
- '908', # Sexual entertainment services
92
- '909', # Sexual entertainment services
93
- '982', # Sexual entertainment services
96
+ '908', # Sexual entertainment services [3+7].
97
+ '909',
98
+ '982',
94
99
  ]
95
100
 
96
- # 6 is the fallback length.
97
- #
98
- no_split = [
99
- '500', # Freephone (9 digits)
101
+ # five_digit_ndc_with_nine_digits
102
+ # Geographic [5+4].
103
+ #
104
+ # '16977', # Brampton (contains both 4 and 5 digit numbers)
105
+ # # 9 digits handled in specific rule, see below.
100
106
 
101
- # Geographic.
107
+ five_digit_ndc = [
108
+ # Geographic [5+5].
102
109
  #
110
+ # These areas use 5-5 format. One area has some 5-4 numbers too (see above).
111
+ # They share their initial digits with area codes using 4-6 (and 4-5).
112
+ '13873', # Langholm
113
+ '15242', # Hornby
114
+ '15394', # Hawkshead
115
+ '15395', # Grange-over-Sands
116
+ '15396', # Sedbergh
117
+ '16973', # Wigton
118
+ '16974', # Raughton Head
119
+ '16977', # Brampton (contains both 4 and 5 digit numbers)
120
+ '17683', # Appleby
121
+ '17684', # Pooley Bridge
122
+ '17687', # Keswick
123
+ '19467', # Gosforth
124
+ ]
125
+
126
+ no_split = [
127
+ # Geographic [4+6]/[4+5].
128
+ #
129
+ # These 40 area codes have a mix of 4-6 and 4-5 numbers
130
+ # The three 'mixed' areas also have part of their number
131
+ # range sub-allocated as 5-5.
103
132
  '1204', # Bolton
104
133
  '1208', # Bodmin
105
134
  '1254', # Blackburn
@@ -141,51 +170,43 @@ no_split = [
141
170
  '1963', # Wincanton
142
171
  '1995', # Garstang
143
172
 
144
- # Geographic.
173
+ # 6 is the fallback length.
174
+ #
175
+ # Mobile [4+6].
145
176
  #
177
+ ('7400'..'7599').to_a,
178
+ '7624',
179
+ ('7700'..'7999').to_a,
180
+
181
+ # Geographic [4+6].
182
+ #
183
+ # About 500 area codes use the 4-6 format
184
+ # The three 'mixed' areas also have part of their number
185
+ # range sub-allocated as 5-5 and one also has some 5-4.
146
186
  '1224', # Aberdeen
147
187
  '1244', # Chester
148
188
  '1382', # Dundee
189
+ '1387', # Dumfries (Mixed area)
149
190
  '1429', # Hartlepool
150
191
  '1482', # Hull
192
+ '1539', # Kendal (Mixed area)
151
193
  '1582', # Luton
152
194
  '1670', # Morpeth
195
+ '1697', # Brampton (Mixed area)
153
196
  '1730', # Petersfield
154
197
  '1736', # Penzance
155
198
  '1772', # Preston
156
199
  '1853', # Ullapool
157
200
  '1947', # Whitby
158
201
  # and 500 others
159
-
160
- # Mobile.
161
- #
162
- ('7400'..'7599').to_a,
163
- '7624',
164
- ('7700'..'7999').to_a,
165
-
166
- # Geographic.
167
- #
168
- # Note: We could remove these and use fixed(5) >> split(5)
169
- # for this as a catchall (see sweden.rb).
170
- #
171
- '13873', # Langholm
172
- '15242', # Hornby
173
- '15394', # Hawkshead
174
- '15395', # Grange-over-Sands
175
- '15396', # Sedbergh
176
- '16973', # Wigton
177
- '16974', # Raughton Head
178
- '16977', # Brampton
179
- '17683', # Appleby
180
- '17684', # Pooley Bridge
181
- '17687', # Keswick
182
- '19467', # Gosforth
183
202
  ].flatten
184
203
 
185
- # '16977', # Brampton -- TODO 016977 + 4 digits for 169772 and 169773
186
-
187
204
  Phony.define do
188
- country '44', one_of(two_digit_ndc) >> split(4,4) |
189
- one_of(three_digit_ndc) >> split(3,4) |
190
- one_of(no_split) >> split(6)
205
+ country '44', one_of(two_digit_ndc) >> split(4,4) | # 2-4-4
206
+ match(/^([58]00)\d{6}$/) >> split(6) | # Special handling for 500 and 800: 3-6 numbers.
207
+ one_of(three_digit_ndc) >> split(3,4) | # 3-3-4
208
+ match(/^(16977)\d{4}$/) >> split(4) | # Special handling for 16977: 5-4 numbers.
209
+ one_of(five_digit_ndc) >> split(5) | # 5-5
210
+ one_of(no_split) >> split(6) | # 4-6 and 4-5
211
+ fixed(4) >> split(6) # Catchall for 4-6 numbers.
191
212
  end
data/lib/phony/country.rb CHANGED
@@ -12,9 +12,7 @@ module Phony
12
12
  @codes = codes
13
13
  end
14
14
 
15
- # DSL.
16
- #
17
- # TODO
15
+ # Chain two codes together.
18
16
  #
19
17
  def |(other)
20
18
  self.codes = self.codes + other.codes
@@ -16,9 +16,9 @@ module Phony
16
16
  # its parts.
17
17
  #
18
18
  def split national_number
19
- zero, ndc, rest = @national_splitter.split national_number.dup
20
- return [zero, ndc] unless rest
21
- [zero, ndc, *@local_splitter.split(rest)]
19
+ zero, ndc_or_rest, rest = @national_splitter.split national_number.dup
20
+ return [zero, ndc_or_rest] unless rest
21
+ [zero, ndc_or_rest, *@local_splitter.split(rest)]
22
22
  end
23
23
 
24
24
  # Split gets a number without country code and removes a relative zero.
@@ -33,6 +33,8 @@ module Phony
33
33
  #
34
34
  # Note: Actually, it might stay in.
35
35
  #
36
+ # TODO Flip nil/false?
37
+ #
36
38
  def split national_number
37
39
  [nil, false, national_number]
38
40
  end
@@ -4,152 +4,156 @@ require 'spec_helper'
4
4
 
5
5
  describe 'country descriptions' do
6
6
 
7
+ def self.it_splits number, expected
8
+ it { Phony.split(number).should == expected }
9
+ end
10
+
7
11
  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 argentine numbers' do
16
- Phony.split('541112345678').should == ['54', '11', '1234', '5678']
17
- Phony.split('542911234567').should == ['54', '291', '123', '4567']
18
- Phony.split('542965123456').should == ['54', '2965', '12', '3456']
19
- Phony.split('5491112345678').should == ['54', '911', '1234', '5678']
20
- Phony.split('5492201234567').should == ['54', '9220', '123', '4567']
21
- Phony.split('5492221123456').should == ['54', '92221', '12', '3456']
22
- end
23
- it 'handles austrian numbers' do
24
- Phony.split('43198110').should == ['43', '1', '98110'] # Vienna
25
- Phony.split('4366914093902').should == ['43', '669', '14093902'] # Mobile
26
- Phony.split('433161234567891').should == ['43', '316', '1234567891'] # Graz
27
- Phony.split('432164123456789').should == ['43', '2164', '123456789'] # Rohrau
28
- end
29
- it 'handles australian numbers' do
30
- Phony.split('61512341234').should == ['61', '5', '1234', '1234'] # Landline
31
- Phony.split('61423123123').should == ['61', '423', '123', '123'] # Mobile
32
- end
33
- it 'handles belgian numbers' do
34
- Phony.split('3235551212').should == ['32', '3', '555', '1212'] # Antwerpen
35
- Phony.split('32505551212').should == ['32', '50', '555', '1212'] # Brugge
36
- Phony.split('3225551212').should == ['32', '2', '555', '1212'] # Brussels
37
- Phony.split('3295551914').should == ['32', '9', '555', '1914'] # Gent
38
- Phony.split('3245551414').should == ['32', '4', '555', '1414'] # Liège
39
- Phony.split('3216473200').should == ['32', '16', '473', '200'] # Leuven
40
- Phony.split('32475279584').should == ['32', '475', '279584'] # mobile
41
- Phony.split('3270123123').should == ['32', '70', '123', '123'] # Bus Service?
42
- end
43
- it 'handles brazilian numbers' do
44
- Phony.split('551112341234').should == ['55', '11', '1234', '1234']
45
- end
46
- it 'handles chilean numbers' do
47
- Phony.split('5621234567').should == ['56', '2', '1234567'] # Santiago
48
- Phony.split('5675123456').should == ['56', '75', '123456'] # Curico
49
- Phony.split('56912345678').should == ['56', '9', '12345678'] # Mobile
50
- Phony.split('56137123456').should == ['56', '137', '123', '456'] # Service
51
- end
52
- it 'handles chinese numbers' do
53
- Phony.split('862112345678').should == ['86', '21', '1234', '5678'] # Shanghai
54
- Phony.split('8675582193447').should == ['86', '755', '8219', '3447'] # Shenzhen
55
- end
56
- it 'handles croatian numbers' do
57
- Phony.split('385112312345').should == ['385', '1', '123', '12345'] # Zagreb
58
- Phony.split('385491231234').should == ['385', '49', '123', '1234'] # Krapina
59
- end
60
- it 'handles cuban numbers' do
61
- Phony.split('5351231234').should == ['53', '5123', '1234'] # Mobile
62
- Phony.split('5371234567').should == ['53', '7', '1234567'] # Havana
63
- Phony.split('5342123456').should == ['53', '42', '123456'] # Villa Clara
64
- end
65
- it 'handles danish numbers' do
66
- Phony.split('4532121212').should == ['45', false, '32', '12', '12', '12']
67
- end
68
- it 'handles dutch numbers' do
69
- Phony.split('31612345678').should == ['31', '6', '12345678'] # mobile
70
- Phony.split('31201234567').should == ['31', '20', '1234567']
71
- Phony.split('31222123456').should == ['31', '222', '123456']
72
- end
73
- it 'handles egyptian numbers' do
74
- Phony.split('20212345678').should == ['20', '2', '12345678']
75
- Phony.split('20921234567').should == ['20', '92', '1234567']
76
- Phony.split('20951234567').should == ['20', '95', '1234567']
77
- end
78
- it 'handles finnish numbers' do
79
- Phony.split('3589123123').should == ['358', '9', '123', '123'] # Helsinki
80
- Phony.split('3581912312').should == ['358', '19', '123', '12'] # Nylandia
81
- Phony.split('3585012312').should == ['358', '50', '123', '12'] # Mobile
82
- Phony.split('358600123').should == ['358', '600', '123'] # Service
83
- end
84
- it 'handles french numbers' do
85
- Phony.split('33112345678').should == ['33', '1', '12','34','56','78'] # Paris
86
- Phony.split('33812345678').should == ['33', '8', '12','34','56','78'] # Service number
87
- end
88
- it 'handles german numbers' do
89
- Phony.split('493038625454').should == ['49', '30', '386', '25454'] # Berlin
90
- Phony.split('4932221764542').should == ['49', '32', '221', '764542'] # Non-Geographical
91
- Phony.split('4922137683323').should == ['49', '221', '376', '83323'] # Cologne
92
- Phony.split('497614767676').should == ['49', '761', '476', '7676'] # Freiburg im Breisgau
93
- Phony.split('4921535100').should == ['49', '2153', '510', '0'] # Nettetal-Lobberich
94
- Phony.split('493434144602').should == ['49', '34341', '446', '02'] # Geithain
95
- Phony.split('491805878323').should == ['49', '180', '587', '8323'] # Service number
96
- Phony.split('491815878323').should == ['49', '181', '587', '8323'] # Service number
97
- end
98
- it 'handles ghanese numbers' do
99
- Phony.split('233302123456').should == ['233', '30', '212', '3456'] # Mobile Vodafone, Accra
100
- end
101
- it 'handles greek numbers' do
102
- Phony.split('3021123456').should == ['30', '21', '123456'] # Athens
103
- Phony.split('3069512345').should == ['30', '695', '12345'] # Mobile
104
- Phony.split('302108131234').should == ['30', '21', '08131234'] # Long mobile, noted by vilcsak in pull request #26.
105
- Phony.split('3025941234').should == ['30', '2594', '1234']
106
- Phony.split('3022631234').should == ['30', '2263', '1234']
107
- end
108
- it 'handles hungarian numbers' do
109
- Phony.split('3612345678').should == ['36', '1', '234', '5678']
110
- Phony.split('3622123456').should == ['36', '22', '123', '456']
111
- end
112
- it 'handles icelandic numbers' do
113
- Phony.split('354112').should == ['354', false, '112'] # Emergency TODO
114
- Phony.split('3544211234').should == ['354', false, '421', '1234'] # Keflavík
115
- Phony.split('3544621234').should == ['354', false, '462', '1234'] # Akureyri
116
- Phony.split('3545511234').should == ['354', false, '551', '1234'] # Reykjavík
117
- end
118
- it 'handles irish numbers' do
119
- Phony.split('35311234567').should == ['353', '1', '123', '4567'] # Dublin, 7 digit subscriber #
120
- Phony.split('3532212345').should == ['353', '22', '12345'] # Mallow, 5 digit subscriber #
121
- Phony.split('35345123456').should == ['353', '45', '123456'] # Naas, 6 digit subscriber #
122
- Phony.split('353801234567').should == ['353', '80', '123', '4567'] # Mobile
123
- Phony.split('353761234567').should == ['353', '76', '123', '4567'] # VoIP
124
- Phony.split('353800123456').should == ['353', '800', '123456'] # Freefone
125
- Phony.split('353000123456').should == ['353', '000', '123456'] # Default fixed 3 split for unrecognized
126
- end
127
- it 'handles italian numbers' do
128
- Phony.split('3934869528').should == ['39', '3486', '952', '8'] # Mobile
129
- Phony.split('390612341234').should == ['39', '06', '1234', '1234'] # Roma
130
- Phony.split('390909709511').should == ['39', '090', '970', '9511'] # Barcellona
131
- end
132
- it 'handles kenyan numbers' do
133
- Phony.split('254201234567').should == ['254', '20', '1234567'] # Nairobi
134
- Phony.split('254111234567').should == ['254', '11', '1234567'] # Mombasa
135
- end
136
- it 'handles lithuanian numbers' do
137
- Phony.split('37070012123').should == ['370', '700', '12', '123'] # Service
138
- Phony.split('37061212123').should == ['370', '612', '12', '123'] # Mobile
139
- Phony.split('37051231212').should == ['370', '5', '123', '12', '12'] # Vilnius
140
- Phony.split('37037121212').should == ['370', '37', '12', '12', '12'] # Kaunas
141
- Phony.split('37044011212').should == ['370', '440', '1', '12', '12'] # Skuodas
142
- end
143
- it 'handles malay numbers' do
144
- Phony.split('6082123456').should == ['60', '82', '123456'] # Kuching
145
- Phony.split('60312345678').should == ['60', '3', '12345678'] # Kuala Lumpur
146
- Phony.split('60212345678').should == ['60', '2', '12345678'] # Singapore
147
- end
148
- it 'handles mexican numbers' do
149
- Phony.split('525512121212').should == ['52', '55', '12', '12', '12', '12'] # Mexico City
150
- Phony.split('526641231212').should == ['52', '664', '123', '12', '12'] # Tijuana
151
- end
152
- it 'handles norwegian numbers' do
12
+ describe 'Afghanistan' do
13
+ it_splits '93201234567', ['93', '20', '1234567'] # Kabul
14
+ end
15
+ describe 'Algeria' do
16
+ it_splits '213211231234', ['213', '21', '123', '1234'] # Algiers
17
+ it_splits '213331231234', ['213', '33', '123', '1234'] # Batna
18
+ end
19
+ describe 'Argentina' do
20
+ it_splits '541112345678', ['54', '11', '1234', '5678']
21
+ it_splits '542911234567', ['54', '291', '123', '4567']
22
+ it_splits '542965123456', ['54', '2965', '12', '3456']
23
+ it_splits '5491112345678', ['54', '911', '1234', '5678']
24
+ it_splits '5492201234567', ['54', '9220', '123', '4567']
25
+ it_splits '5492221123456', ['54', '92221', '12', '3456']
26
+ end
27
+ describe 'Austria' do
28
+ it_splits '43198110', ['43', '1', '98110'] # Vienna
29
+ it_splits '4366914093902', ['43', '669', '14093902'] # Mobile
30
+ it_splits '433161234567891', ['43', '316', '1234567891'] # Graz
31
+ it_splits '432164123456789', ['43', '2164', '123456789'] # Rohrau
32
+ end
33
+ describe 'Australia' do
34
+ it_splits '61512341234', ['61', '5', '1234', '1234'] # Landline
35
+ it_splits '61423123123', ['61', '423', '123', '123'] # Mobile
36
+ end
37
+ describe 'Belgium' do
38
+ it_splits '3235551212', ['32', '3', '555', '1212'] # Antwerpen
39
+ it_splits '32505551212', ['32', '50', '555', '1212'] # Brugge
40
+ it_splits '3225551212', ['32', '2', '555', '1212'] # Brussels
41
+ it_splits '3295551914', ['32', '9', '555', '1914'] # Gent
42
+ it_splits '3245551414', ['32', '4', '555', '1414'] # Liège
43
+ it_splits '3216473200', ['32', '16', '473', '200'] # Leuven
44
+ it_splits '32475279584', ['32', '475', '279584'] # mobile
45
+ it_splits '3270123123', ['32', '70', '123', '123'] # Bus Service?
46
+ end
47
+ describe 'Brazil' do
48
+ it_splits '551112341234', ['55', '11', '1234', '1234']
49
+ end
50
+ describe 'Chile' do
51
+ it_splits '5621234567', ['56', '2', '1234567'] # Santiago
52
+ it_splits '5675123456', ['56', '75', '123456'] # Curico
53
+ it_splits '56912345678', ['56', '9', '12345678'] # Mobile
54
+ it_splits '56137123456', ['56', '137', '123', '456'] # Service
55
+ end
56
+ describe 'China' do
57
+ it_splits '862112345678', ['86', '21', '1234', '5678'] # Shanghai
58
+ it_splits '8675582193447', ['86', '755', '8219', '3447'] # Shenzhen
59
+ end
60
+ describe 'Croatia' do
61
+ it_splits '385112312345', ['385', '1', '123', '12345'] # Zagreb
62
+ it_splits '385491231234', ['385', '49', '123', '1234'] # Krapina
63
+ end
64
+ describe 'Cuba' do
65
+ it_splits '5351231234', ['53', '5123', '1234'] # Mobile
66
+ it_splits '5371234567', ['53', '7', '1234567'] # Havana
67
+ it_splits '5342123456', ['53', '42', '123456'] # Villa Clara
68
+ end
69
+ describe 'Denmark' do
70
+ it_splits '4532121212', ['45', false, '32', '12', '12', '12']
71
+ end
72
+ describe 'Egypt' do
73
+ it_splits '20212345678', ['20', '2', '12345678']
74
+ it_splits '20921234567', ['20', '92', '1234567']
75
+ it_splits '20951234567', ['20', '95', '1234567']
76
+ end
77
+ describe 'Finland' do
78
+ it_splits '3589123123', ['358', '9', '123', '123'] # Helsinki
79
+ it_splits '3581912312', ['358', '19', '123', '12'] # Nylandia
80
+ it_splits '3585012312', ['358', '50', '123', '12'] # Mobile
81
+ it_splits '358600123', ['358', '600', '123'] # Service
82
+ end
83
+ describe 'France' do
84
+ it_splits '33112345678', ['33', '1', '12','34','56','78'] # Paris
85
+ it_splits '33812345678', ['33', '8', '12','34','56','78'] # Service number
86
+ end
87
+ describe 'Germany' do
88
+ it_splits '493038625454', ['49', '30', '386', '25454'] # Berlin
89
+ it_splits '4932221764542', ['49', '32', '221', '764542'] # Non-Geographical
90
+ it_splits '4922137683323', ['49', '221', '376', '83323'] # Cologne
91
+ it_splits '497614767676', ['49', '761', '476', '7676'] # Freiburg im Breisgau
92
+ it_splits '4921535100', ['49', '2153', '510', '0'] # Nettetal-Lobberich
93
+ it_splits '493434144602', ['49', '34341', '446', '02'] # Geithain
94
+ it_splits '491805878323', ['49', '180', '587', '8323'] # Service number
95
+ it_splits '491815878323', ['49', '181', '587', '8323'] # Service number
96
+ end
97
+ describe 'Ghana' do
98
+ it_splits '233302123456', ['233', '30', '212', '3456'] # Mobile Vodafone, Accra
99
+ end
100
+ describe 'Greece' do
101
+ it_splits '3021123456', ['30', '21', '123456'] # Athens
102
+ it_splits '3069512345', ['30', '695', '12345'] # Mobile
103
+ it_splits '302108131234', ['30', '21', '08131234'] # Long mobile, noted by vilcsak in pull request #26.
104
+ it_splits '3025941234', ['30', '2594', '1234']
105
+ it_splits '3022631234', ['30', '2263', '1234']
106
+ end
107
+ describe 'Hungary' do
108
+ it_splits'3612345678', ['36', '1', '234', '5678']
109
+ it_splits'3622123456', ['36', '22', '123', '456']
110
+ end
111
+ describe 'Iceland' do
112
+ it_splits '354112', ['354', false, '112'] # Emergency TODO
113
+ it_splits '3544211234', ['354', false, '421', '1234'] # Keflavík
114
+ it_splits '3544621234', ['354', false, '462', '1234'] # Akureyri
115
+ it_splits '3545511234', ['354', false, '551', '1234'] # Reykjavík
116
+ end
117
+ describe 'Ireland' do
118
+ it_splits '35311234567', ['353', '1', '123', '4567'] # Dublin, 7 digit subscriber #
119
+ it_splits '3532212345', ['353', '22', '12345'] # Mallow, 5 digit subscriber #
120
+ it_splits '35345123456', ['353', '45', '123456'] # Naas, 6 digit subscriber #
121
+ it_splits '353801234567', ['353', '80', '123', '4567'] # Mobile
122
+ it_splits '353761234567', ['353', '76', '123', '4567'] # VoIP
123
+ it_splits '353800123456', ['353', '800', '123456'] # Freefone
124
+ it_splits '353000123456', ['353', '000', '123456'] # Default fixed 3 split for unrecognized
125
+ end
126
+ describe 'Italy' do
127
+ it_splits '3934869528', ['39', '3486', '952', '8'] # Mobile
128
+ it_splits '390612341234', ['39', '06', '1234', '1234'] # Roma
129
+ it_splits '390909709511', ['39', '090', '970', '9511'] # Barcellona
130
+ end
131
+ describe 'Kenya' do
132
+ it { Phony.split('254201234567').should == ['254', '20', '1234567'] } # Nairobi
133
+ it { Phony.split('254111234567').should == ['254', '11', '1234567'] } # Mombasa
134
+ end
135
+ describe 'Lithuania' do
136
+ it { Phony.split('37070012123').should == ['370', '700', '12', '123'] } # Service
137
+ it { Phony.split('37061212123').should == ['370', '612', '12', '123'] } # Mobile
138
+ it { Phony.split('37051231212').should == ['370', '5', '123', '12', '12'] } # Vilnius
139
+ it { Phony.split('37037121212').should == ['370', '37', '12', '12', '12'] } # Kaunas
140
+ it { Phony.split('37044011212').should == ['370', '440', '1', '12', '12'] } # Skuodas
141
+ end
142
+ describe 'Malaysia' do
143
+ it { Phony.split('6082123456').should == ['60', '82', '123456'] } # Kuching
144
+ it { Phony.split('60312345678').should == ['60', '3', '12345678'] } # Kuala Lumpur
145
+ it { Phony.split('60212345678').should == ['60', '2', '12345678'] } # Singapore
146
+ end
147
+ describe 'Mexico' do
148
+ it { Phony.split('525512121212').should == ['52', '55', '12', '12', '12', '12'] } # Mexico City
149
+ it { Phony.split('526641231212').should == ['52', '664', '123', '12', '12'] } # Tijuana
150
+ end
151
+ describe 'The Netherlands' do
152
+ it { Phony.split('31612345678').should == ['31', '6', '12345678'] } # mobile
153
+ it { Phony.split('31201234567').should == ['31', '20', '1234567'] }
154
+ it { Phony.split('31222123456').should == ['31', '222', '123456'] }
155
+ end
156
+ describe 'Norway' do
153
157
  Phony.split('4721234567').should == ['47',false,'21','23','45','67']
154
158
  Phony.split('4731234567').should == ['47',false,'31','23','45','67']
155
159
  Phony.split('4741234567').should == ['47',false,'412','34','567']
@@ -159,114 +163,122 @@ describe 'country descriptions' do
159
163
  Phony.split('4781234567').should == ['47',false,'812','34','567']
160
164
  Phony.split('4791234567').should == ['47',false,'912','34','567']
161
165
  end
162
- it 'handles peruvian numbers' do
166
+ describe 'Peru' do
163
167
  Phony.split('51112341234').should == ['51', '1', '1234', '1234'] # Lima
164
168
  Phony.split('51912341234').should == ['51', '9', '1234', '1234'] # mobile
165
169
  Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
166
170
  end
167
- it 'handles polish numbers' do
171
+ describe 'Poland' do
168
172
  Phony.split('48123456789').should == ['48', '12', '345', '67', '89'] # Landline
169
173
  Phony.split('48501123456').should == ['48', '501', '123', '456'] # Mobile
170
174
  Phony.split('48800123456').should == ['48', '800', '123', '456'] # Free
171
175
  Phony.split('48801123456').should == ['48', '801', '123', '456'] # Shared cost
172
176
  Phony.split('48701123456').should == ['48', '701', '123', '456'] # Premium
173
177
  end
174
- it 'handles portuguese numbers' do
178
+ describe 'Portugal' do
175
179
  Phony.split('351211231234').should == ['351', '21', '123', '1234'] # Lisboa
176
180
  Phony.split('351241123123').should == ['351', '241', '123', '123'] # Abrantes
177
181
  Phony.split('351931231234').should == ['351', '93', '123', '1234'] # mobile
178
182
  end
179
- it 'handles romanian numbers' do
180
- Phony.split('40211231234').should == ['40', '21', '123', '1234'] # Bucureşti
181
- Phony.split('40721231234').should == ['40', '72', '123', '1234'] # mobile
182
- Phony.split('40249123123').should == ['40', '249', '123', '123'] # Olt
183
- end
184
- it 'handles russian numbers' do
185
- Phony.split('78122345678').should == ['7', '812', '234', '56', '78'] # Russia 3-digit
186
- Phony.split('74012771077').should == ['7', '4012', '77', '10', '77'] # Russia 4-digit
187
- Phony.split('78402411212').should == ['7', '84024', '1', '12', '12'] # Russia 5-digit
188
- Phony.split('7840121212').should == ['7', '840', '12', '12', '12'] # Abhasia
189
- Phony.split('7209175276').should == ['7', '209', '17', '52', '76'] # Fantasy number
190
- end
191
- it 'handles south korean numbers' do
192
- Phony.split('82212345678').should == ['82', '2', '1234', '5678'] # Seoul
193
- Phony.split('825112345678').should == ['82', '51', '1234', '5678'] # Busan
194
- Phony.split('821027975588').should == ['82', '10', '2797', '5588'] # mobile
195
- Phony.split('821087971234').should == ['82', '10', '8797', '1234'] # mobile
196
- end
197
- it 'handles thai numbers' do
198
- Phony.split('6621231234').should == ['66', '2', '123', '1234'] # Bangkok
199
- Phony.split('6636123123').should == ['66', '36', '123', '123'] # Lop Buri
200
- end
201
- it 'handles tunisian numbers' do
202
- Phony.split('21611231234').should == ['216', '1', '123', '1234'] # Ariana
203
- Phony.split('21621231234').should == ['216', '2', '123', '1234'] # Bizerte
204
- end
205
- it 'handles singaporean numbers' do
206
- Phony.split('6561231234').should == ['65', false, '6123', '1234'] # Fixed line
207
- end
208
- it 'handles slovakian numbers' do
209
- Phony.split('421912123456').should == ['421', '912', '123456'] # Mobile
210
- Phony.split('421212345678').should == ['421', '2', '12345678'] # Bratislava
211
- Phony.split('421371234567').should == ['421', '37', '1234567'] # Nitra / Other
212
- end
213
- it 'handles swedish numbers' do
214
- Phony.split('46812345678').should == ['46', '8', '12345678'] # Stockholm
215
- Phony.split('46111234567').should == ['46', '11', '1234567']
216
- Phony.split('46125123456').should == ['46', '125', '123456']
217
- end
218
- it 'handles swiss numbers' do
219
- Phony.split('41443643532').should == ['41', '44', '364', '35', '32'] # Zurich (usually)
220
- Phony.split('41800334455').should == ['41', '800', '334', '455'] # Service number
221
- end
222
- it 'handles tanzanian numbers' do
223
- Phony.split('255221231234').should == ['255', '22', '123', '1234'] # Dar Es Salaam
224
- Phony.split('255651231234').should == ['255', '65', '123', '1234'] # TIGO
225
- Phony.split('255861123123').should == ['255', '861', '123', '123'] # Special Rates
226
- end
227
- it 'handles turkish numbers' do
228
- Phony.split('903121234567').should == ['90', '312', '123', '4567'] # Ankara
229
- end
230
- it 'handles ugandan numbers' do
231
- Phony.split('256414123456').should == ['256', '41', '4123456'] # Kampania
232
- Phony.split('256464441234').should == ['256', '464', '441234'] # Mubende
233
- end
234
- it 'handles UK numbers' do
235
- Phony.split('442075671113').should == ['44', '20', '7567', '1113'] # London
236
- Phony.split('442920229901').should == ['44', '29', '2022', '9901'] # Cardiff
237
- Phony.split('441134770011').should == ['44', '113', '477', '0011'] # Leeds
238
- Phony.split('441412770011').should == ['44', '141', '277', '0011'] # Glasgow
239
- Phony.split('441382229845').should == ['44', '1382', '229845'] # Dundee
240
- Phony.split('441204500532').should == ['44', '1204', '500532'] # Bolton
241
- Phony.split('44120462532').should == ['44', '1204', '62532'] # Bolton
242
- Phony.split('441539648756').should == ['44', '15396', '48756'] # Sedbergh
243
- Phony.split('441697744555').should == ['44', '16977', '44555'] # Brampton
244
- Phony.split('44169772333').should == ['44', '16977', '2333'] # Brampton
245
- Phony.split('443005878323').should == ['44', '300', '587', '8323'] # Non-geographic
246
- Phony.split('443457777334').should == ['44', '345', '777', '7334'] # Non-geographic
247
- Phony.split('44500557788').should == ['44', '500', '557788'] # Freefone
248
- Phony.split('445575671113').should == ['44', '55', '7567', '1113'] # Corporate
249
- Phony.split('445644775533').should == ['44', '56', '4477', '5533'] # LIECS/VoIP
250
- Phony.split('447020229901').should == ['44', '70', '2022', '9901'] # Personal numbers
251
- Phony.split('447780605207').should == ['44', '7780', '605207'] # Mobile
252
- Phony.split('447480605207').should == ['44', '7480', '605207'] # Mobile
253
- # Phony.split('44800557788').should == ['44', '800', '557788'] # Freefone
254
- Phony.split('448084682355').should == ['44', '808', '468', '2355'] # Freefone
255
- Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Freefone, regression
256
- end
257
- it 'handles US numbers' do
258
- Phony.split('15551115511').should == ['1', '555', '111', '5511']
259
- end
260
- it 'handles venezuelan numbers' do
261
- Phony.split('582121234567').should == ['58', '212', '1234567']
262
- end
263
- it 'handles vietnamese numbers' do
264
- Phony.split('8498123456').should == ['84', '98', '123456'] # Viettel Mobile
265
- Phony.split('8499612345').should == ['84', '996', '12345'] # GTel
266
- Phony.split('8441234567').should == ['84', '4', '1234567'] # Hanoi
267
- end
268
- it 'handles new zealand / kiwi numbers' do
269
- Phony.split('6491234567').should == ['64', '9', '123', '4567']
183
+ describe 'Romania' do
184
+ it { Phony.split('40211231234').should == ['40', '21', '123', '1234'] } # Bucureşti
185
+ it { Phony.split('40721231234').should == ['40', '72', '123', '1234'] } # mobile
186
+ it { Phony.split('40249123123').should == ['40', '249', '123', '123'] } # Olt
187
+ end
188
+ describe 'Russia' do
189
+ it { Phony.split('78122345678').should == ['7', '812', '234', '56', '78'] } # Russia 3-digit
190
+ it { Phony.split('74012771077').should == ['7', '4012', '77', '10', '77'] } # Russia 4-digit
191
+ it { Phony.split('78402411212').should == ['7', '84024', '1', '12', '12'] } # Russia 5-digit
192
+ it { Phony.split('7840121212').should == ['7', '840', '12', '12', '12'] } # Abhasia
193
+ it { Phony.split('7799121212').should == ['7', '799', '12', '12', '12'] } # Kazachstan
194
+ it { Phony.split('7995344121212').should == ['7','995344','12','12','12'] } # South Osetia
195
+ it { Phony.split('7209175276').should == ['7', '209', '17', '52', '76'] } # Fantasy number
196
+ end
197
+ describe 'South Korea' do
198
+ it { Phony.split('82212345678').should == ['82', '2', '1234', '5678'] } # Seoul
199
+ it { Phony.split('825112345678').should == ['82', '51', '1234', '5678'] } # Busan
200
+ it { Phony.split('821027975588').should == ['82', '10', '2797', '5588'] } # mobile
201
+ it { Phony.split('821087971234').should == ['82', '10', '8797', '1234'] } # mobile
202
+ end
203
+ describe 'Thailand' do
204
+ it { Phony.split('6621231234').should == ['66', '2', '123', '1234'] } # Bangkok
205
+ it { Phony.split('6636123123').should == ['66', '36', '123', '123'] } # Lop Buri
206
+ end
207
+ describe 'Tunesia' do
208
+ it { Phony.split('21611231234').should == ['216', '1', '123', '1234'] } # Ariana
209
+ it { Phony.split('21621231234').should == ['216', '2', '123', '1234'] } # Bizerte
210
+ end
211
+ describe 'Singapore' do
212
+ it { Phony.split('6561231234').should == ['65', false, '6123', '1234'] } # Fixed line
213
+ end
214
+ describe 'Slovakia' do
215
+ it { Phony.split('421912123456').should == ['421', '912', '123456'] } # Mobile
216
+ it { Phony.split('421212345678').should == ['421', '2', '12345678'] } # Bratislava
217
+ it { Phony.split('421371234567').should == ['421', '37', '1234567'] } # Nitra / Other
218
+ end
219
+ describe 'Sweden' do
220
+ it { Phony.split('46812345678').should == ['46', '8', '12345678'] } # Stockholm
221
+ it { Phony.split('46111234567').should == ['46', '11', '1234567'] }
222
+ it { Phony.split('46125123456').should == ['46', '125', '123456'] }
223
+ end
224
+ describe 'Switzerland' do
225
+ it { Phony.split('41443643532').should == ['41', '44', '364', '35', '32'] } # Zurich (usually)
226
+ it { Phony.split('41800334455').should == ['41', '800', '334', '455'] } # Service number
227
+ end
228
+ describe 'Tanzania' do
229
+ it { Phony.split('255221231234').should == ['255', '22', '123', '1234'] } # Dar Es Salaam
230
+ it { Phony.split('255651231234').should == ['255', '65', '123', '1234'] } # TIGO
231
+ it { Phony.split('255861123123').should == ['255', '861', '123', '123'] } # Special Rates
232
+ end
233
+ describe 'Turkey' do
234
+ it { Phony.split('903121234567').should == ['90', '312', '123', '4567'] } # Ankara
235
+ end
236
+ describe 'Uganda' do
237
+ it { Phony.split('256414123456').should == ['256', '41', '4123456'] } # Kampania
238
+ it { Phony.split('256464441234').should == ['256', '464', '441234'] } # Mubende
239
+ end
240
+ describe 'The UK' do
241
+ it { Phony.split('442075671113').should == ['44', '20', '7567', '1113'] } # London
242
+ it { Phony.split('442920229901').should == ['44', '29', '2022', '9901'] } # Cardiff
243
+ it { Phony.split('441134770011').should == ['44', '113', '477', '0011'] } # Leeds
244
+ it { Phony.split('441412770022').should == ['44', '141', '277', '0022'] } # Glasgow
245
+ it { Phony.split('441204500532').should == ['44', '1204', '500532'] } # Bolton
246
+ it { Phony.split('44120462532').should == ['44', '1204', '62532'] } # Bolton
247
+ it { Phony.split('441382229845').should == ['44', '1382', '229845'] } # Dundee
248
+ it { Phony.split('441539248756').should == ['44', '1539', '248756'] } # Kendal
249
+ it { Phony.split('441539648788').should == ['44', '15396', '48788'] } # Sedbergh
250
+ it { Phony.split('441697222555').should == ['44', '1697', '222555'] } # Brampton
251
+ it { Phony.split('441697388555').should == ['44', '16973', '88555'] } # Wigton
252
+ it { Phony.split('44169772333').should == ['44', '16977', '2333'] } # Brampton
253
+ it { Phony.split('441697744888').should == ['44', '16977', '44888'] } # Brampton
254
+ it { Phony.split('441946555777').should == ['44', '1946', '555777'] } # Whitehaven
255
+ it { Phony.split('44194662888').should == ['44', '1946', '62888'] } # Whitehaven
256
+ it { Phony.split('441946722444').should == ['44', '19467', '22444'] } # Gosforth
257
+ it { Phony.split('443005878323').should == ['44', '300', '587', '8323'] } # Non-geographic
258
+ it { Phony.split('443457777334').should == ['44', '345', '777', '7334'] } # Non-geographic
259
+ it { Phony.split('44500557788').should == ['44', '500', '557788'] } # Freefone 500 + 6
260
+ it { Phony.split('445575671113').should == ['44', '55', '7567', '1113'] } # Corporate
261
+ it { Phony.split('445644775533').should == ['44', '56', '4477', '5533'] } # LIECS/VoIP
262
+ it { Phony.split('447020229901').should == ['44', '70', '2022', '9901'] } # Personal numbers
263
+ it { Phony.split('447780605207').should == ['44', '7780', '605207'] } # Mobile
264
+ it { Phony.split('447480605207').should == ['44', '7480', '605207'] } # Mobile
265
+ it { Phony.split('44800557788').should == ['44', '800', '557788'] } # Freefone 800 + 6
266
+ it { Phony.split('448084682355').should == ['44', '808', '468', '2355'] } # Freefone
267
+ it { Phony.split('448005878323').should == ['44', '800', '587', '8323'] } # Freefone, regression
268
+ end
269
+ describe 'US' do
270
+ it { Phony.split('15551115511').should == ['1', '555', '111', '5511'] }
271
+ end
272
+ describe 'Venezuela' do
273
+ it { Phony.split('582121234567').should == ['58', '212', '1234567'] }
274
+ end
275
+ describe 'Vietnam' do
276
+ it { Phony.split('8498123456').should == ['84', '98', '123456'] } # Viettel Mobile
277
+ it { Phony.split('8499612345').should == ['84', '996', '12345'] } # GTel
278
+ it { Phony.split('8441234567').should == ['84', '4', '1234567'] } # Hanoi
279
+ end
280
+ describe 'New Zealand' do
281
+ it { Phony.split('6491234567').should == ['64', '9', '123', '4567'] }
270
282
  end
271
283
  end
272
284
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.10
4
+ version: 1.7.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Fast international phone number (E164 standard) normalizing, splitting
15
15
  and formatting. Lots of formatting options: International (+.., 00..), national