phony 1.7.9 → 1.7.10

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.
@@ -1,4 +1,5 @@
1
- # The United Kingdom uses a variable-length ndc code, 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 all_other.rb explode.
2
3
  #
3
4
  # Note: The United Kingdom uses a variable ndc format from length 2 to 5.
4
5
  #
@@ -9,13 +10,13 @@
9
10
  # a 5 or 4 formatting rule with area codes that are 5 digits long.
10
11
  #
11
12
  # To reflect this different formatting, we need to install all handlers in a row.
12
- # First, the area codes of length 2, without a fallback length (since this captures all), but with a nil fallback length.
13
+ # First, the area codes of length 2, without a fallback length (since this
14
+ # captures all), but with a nil fallback length.
13
15
  #
14
16
  # TODO Implement and use length-based splitter.
15
17
  #
16
- handlers = []
17
18
 
18
- area_code_2_national = Phony::NationalSplitters::Variable.new nil, [
19
+ two_digit_ndc = [
19
20
  '20', # London
20
21
  '23', # Southampton, Portsmith
21
22
  '24', # Coventry
@@ -24,12 +25,9 @@ area_code_2_national = Phony::NationalSplitters::Variable.new nil, [
24
25
  '55', # Corporate
25
26
  '56', # LIECS/VoIP
26
27
  '70', # Personal numbers
27
-
28
28
  ]
29
- area_code_2_local = Phony::LocalSplitters::Fixed.instance_for [4, 4]
30
- handlers << Phony::NationalCode.new(area_code_2_national, area_code_2_local)
31
29
 
32
- area_code_3_national = Phony::NationalSplitters::Variable.new nil, [
30
+ three_digit_ndc = [
33
31
  # Geographic.
34
32
  #
35
33
  '113', # Leeds
@@ -68,7 +66,6 @@ area_code_3_national = Phony::NationalSplitters::Variable.new nil, [
68
66
  '372',
69
67
  '373',
70
68
 
71
- # '500', # Freephone (9 digits) -- to do 0500 + 6 digits
72
69
  '800', # Freephone (9 or 10 digits)
73
70
  '808', # Freephone (10 digits)
74
71
 
@@ -95,12 +92,12 @@ area_code_3_national = Phony::NationalSplitters::Variable.new nil, [
95
92
  '909', # Sexual entertainment services
96
93
  '982', # Sexual entertainment services
97
94
  ]
98
- area_code_3_local = Phony::LocalSplitters::Fixed.instance_for [3, 4]
99
- handlers << Phony::NationalCode.new(area_code_3_national, area_code_3_local)
100
95
 
101
96
  # 6 is the fallback length.
102
97
  #
103
- area_code_45_national = Phony::NationalSplitters::Variable.new 6, [
98
+ no_split = [
99
+ '500', # Freephone (9 digits)
100
+
104
101
  # Geographic.
105
102
  #
106
103
  '1204', # Bolton
@@ -168,6 +165,9 @@ area_code_45_national = Phony::NationalSplitters::Variable.new 6, [
168
165
 
169
166
  # Geographic.
170
167
  #
168
+ # Note: We could remove these and use fixed(5) >> split(5)
169
+ # for this as a catchall (see sweden.rb).
170
+ #
171
171
  '13873', # Langholm
172
172
  '15242', # Hornby
173
173
  '15394', # Hawkshead
@@ -181,11 +181,11 @@ area_code_45_national = Phony::NationalSplitters::Variable.new 6, [
181
181
  '17687', # Keswick
182
182
  '19467', # Gosforth
183
183
  ].flatten
184
- area_code_45_local = Phony::LocalSplitters::Fixed.instance_for [6]
185
- handlers << Phony::NationalCode.new(area_code_45_national, area_code_45_local)
186
184
 
187
- # '16977', # Brampton -- to do 016977 + 4 digits for 169772 and 169773
185
+ # '16977', # Brampton -- TODO 016977 + 4 digits for 169772 and 169773
188
186
 
189
187
  Phony.define do
190
- country '44', Phony::Country.new(*handlers)
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)
191
191
  end
@@ -82,7 +82,8 @@ describe 'country descriptions' do
82
82
  Phony.split('358600123').should == ['358', '600', '123'] # Service
83
83
  end
84
84
  it 'handles french numbers' do
85
- Phony.split('33112345678').should == ['33', '1', '12','34','56','78']
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
86
87
  end
87
88
  it 'handles german numbers' do
88
89
  Phony.split('493038625454').should == ['49', '30', '386', '25454'] # Berlin
@@ -91,8 +92,8 @@ describe 'country descriptions' do
91
92
  Phony.split('497614767676').should == ['49', '761', '476', '7676'] # Freiburg im Breisgau
92
93
  Phony.split('4921535100').should == ['49', '2153', '510', '0'] # Nettetal-Lobberich
93
94
  Phony.split('493434144602').should == ['49', '34341', '446', '02'] # Geithain
94
- Phony.split('491805878323').should == ['49', '180', '587', '8323'] # Service numbers
95
- Phony.split('491815878323').should == ['49', '181', '587', '8323'] # Service numbers
95
+ Phony.split('491805878323').should == ['49', '180', '587', '8323'] # Service number
96
+ Phony.split('491815878323').should == ['49', '181', '587', '8323'] # Service number
96
97
  end
97
98
  it 'handles ghanese numbers' do
98
99
  Phony.split('233302123456').should == ['233', '30', '212', '3456'] # Mobile Vodafone, Accra
@@ -215,7 +216,8 @@ describe 'country descriptions' do
215
216
  Phony.split('46125123456').should == ['46', '125', '123456']
216
217
  end
217
218
  it 'handles swiss numbers' do
218
- Phony.split('41443643532').should == ['41', '44', '364', '35', '32']
219
+ Phony.split('41443643532').should == ['41', '44', '364', '35', '32'] # Zurich (usually)
220
+ Phony.split('41800334455').should == ['41', '800', '334', '455'] # Service number
219
221
  end
220
222
  it 'handles tanzanian numbers' do
221
223
  Phony.split('255221231234').should == ['255', '22', '123', '1234'] # Dar Es Salaam
@@ -242,13 +244,13 @@ describe 'country descriptions' do
242
244
  Phony.split('44169772333').should == ['44', '16977', '2333'] # Brampton
243
245
  Phony.split('443005878323').should == ['44', '300', '587', '8323'] # Non-geographic
244
246
  Phony.split('443457777334').should == ['44', '345', '777', '7334'] # Non-geographic
245
- # Phony.split('44500557788').should == ['44', '500', '557788'] # Freefone
247
+ Phony.split('44500557788').should == ['44', '500', '557788'] # Freefone
246
248
  Phony.split('445575671113').should == ['44', '55', '7567', '1113'] # Corporate
247
249
  Phony.split('445644775533').should == ['44', '56', '4477', '5533'] # LIECS/VoIP
248
250
  Phony.split('447020229901').should == ['44', '70', '2022', '9901'] # Personal numbers
249
251
  Phony.split('447780605207').should == ['44', '7780', '605207'] # Mobile
250
252
  Phony.split('447480605207').should == ['44', '7480', '605207'] # Mobile
251
- # Phony.split('44800557788').should == ['44', '800', '557788'] # Freefone
253
+ # Phony.split('44800557788').should == ['44', '800', '557788'] # Freefone
252
254
  Phony.split('448084682355').should == ['44', '808', '468', '2355'] # Freefone
253
255
  Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Freefone, regression
254
256
  end
@@ -263,16 +265,9 @@ describe 'country descriptions' do
263
265
  Phony.split('8499612345').should == ['84', '996', '12345'] # GTel
264
266
  Phony.split('8441234567').should == ['84', '4', '1234567'] # Hanoi
265
267
  end
266
- it 'handles new zealand numbers' do
268
+ it 'handles new zealand / kiwi numbers' do
267
269
  Phony.split('6491234567').should == ['64', '9', '123', '4567']
268
270
  end
269
-
270
- it 'handles french service numbers' do
271
- Phony.split('33812345678').should == ['33', '8', '12','34','56','78']
272
- end
273
- it 'handles swiss service numbers' do
274
- Phony.split('41800334455').should == ['41', '800', '334', '455']
275
- end
276
271
  end
277
272
 
278
273
  end
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.9
4
+ version: 1.7.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: