Permalink
Browse files

Additional GB phone number ranges defined.

Add more GB test numbers and ensure all GB test numbers are in valid prefixes and ranges.

Tidy various RegEx patterns and fix an obvious typo.
  • Loading branch information...
1 parent 501ecc8 commit dc8cc179c983ea8addf3cd37c1abf7fc76f72343 @g1smd g1smd committed Aug 19, 2012
Showing with 119 additions and 28 deletions.
  1. +5 −5 lib/phony/countries.rb
  2. +1 −1 lib/phony/countries/sweden.rb
  3. +96 −16 lib/phony/countries/united_kingdom.rb
  4. +17 −6 spec/lib/phony/countries_spec.rb
@@ -45,7 +45,7 @@
country '20', one_of('800') >> split(7) | # Egypt
one_of('2', '3') >> split(8) | # Cairo/Giza, Alexandria
fixed(2) >> split(8)
- # :mobile? => /^10|11|12|14|16|17|18|19*$/, :service? => /^800.*$/
+ # :mobile? => /^1[01246-9]\d+$/, :service? => /^800\d+$/
# South Africa.
#
@@ -96,7 +96,7 @@
# Switzerland.
#
country '41',
- match(/^(8(00|40|42|44|48))\d+$/) >> split(3,3) |
+ match(/^(8(00|4[0248]))\d+$/) >> split(3,3) |
fixed(2) >> split(3,2,2)
@@ -145,7 +145,7 @@
#
country '53',
match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
- match(/^(7|21|22|23|4[1-8]|3[1-3])/) >> split(7) | # Short NDCs
+ match(/^(7|2[123]|4[1-8]|3[1-3])/) >> split(7) | # Short NDCs
fixed(3) >> split(7) # 3-digit NDCs
# Argentine Republic.
@@ -160,7 +160,7 @@
# Brazil (Federative Republic of).
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
#
- brazilian_service = /^(100|128|190|191|192|193|194|197|198|199)\d+$/
+ brazilian_service = /^(1(00|28|9[0-4789]))\d+$/
country '55',
match(brazilian_service) >> split(3,3) | # Service.
fixed(2) >> split(4,4) # NDCs
@@ -241,7 +241,7 @@
country '98', fixed(2) >> split(3,2,2) # TODO Iran (Islamic Republic of)
country '210', todo # -
- country '211', todo # -
+ country '211', todo # South Sudan
country '212', todo # Morocco
country '213', fixed(2) >> split(3,4) # Algeria
country '214', todo # -
@@ -8,7 +8,7 @@
#
ndcs = [
- '7', # Non-geographical
+ '7', # Non-geographic
'8', # Stockholm
'10', # VOIP
'11', # Norrköping
@@ -1,9 +1,12 @@
# The United Kingdom uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
#
-# Note: The United Kingdom uses a variable ndc format from length 2 to 6.
+# Note: The United Kingdom uses a variable ndc format from length 2 to 5.
#
-# The UK is special in formatting in that it uses a 4-4, or 3-4 formatting rule with area
-# codes that are 2 or 3 digits long, and a 6 formatting rule with area codes that are 4-6 digits long.
+# The UK is special in formatting in that it uses:
+# a 4-4 formatting rule with area codes that are 2 digits long,
+# a 3-4 formatting rule with area codes that are 3 digits long,
+# a 6 or 5 formatting rule with area codes that are 4 digits long, and
+# a 5 or 4 formatting rule with area codes that are 5 digits long.
#
# To reflect this different formatting, we need to install all handlers in a row.
# First, the area codes of length 2, without a fallback length (since this captures all), but with a nil fallback length.
@@ -18,12 +21,16 @@
'24', # Coventry
'28', # Northern Ireland
'29', # Cardiff
+ '55', # Corporate
+ '56', # LIECS/VoIP
+ '70', # Personal numbers
+
]
area_code_2_local = Phony::LocalSplitters::Fixed.instance_for [4, 4]
handlers << Phony::NationalCode.new(area_code_2_national, area_code_2_local)
area_code_3_national = Phony::NationalSplitters::Variable.new nil, [
- # Geographical.
+ # Geographic.
#
'113', # Leeds
'114', # Sheffield
@@ -39,19 +46,51 @@
'171', # Used for inner London until 2000
'181', # Used for outer London until 2000
'191', # Tyne and Wear/County Durham
+
# Services.
#
- '800', # Freephone
- '808', # Freephone
- '842',
+ '300', # Non-geographic charged at same rate as 01
+ '301',
+ '303',
+ '308',
+ '309',
+ '330',
+ '331',
+ '333',
+ '336',
+ '339',
+ '342',
+ '343',
+ '344',
+ '345',
+ '370',
+ '371',
+ '372',
+ '373',
+
+ '500', # Freephone (9 digits)
+ '800', # Freephone (9 or 10 digits)
+ '808', # Freephone (10 digits)
+
+ '842', # Business rate
'843',
'844',
'845',
'870',
- '871',
+
+ '871', # Premium rate
'872',
'873',
+
'900', # Premium rate content services
+ '901',
+ '902',
+ '903',
+ '904',
+ '905',
+ '906',
+ '907',
+
'908', # Sexual entertainment services
'909', # Sexual entertainment services
'982', # Sexual entertainment services
@@ -62,31 +101,72 @@
# 6 is the fallback length.
#
area_code_45_national = Phony::NationalSplitters::Variable.new 6, [
- # Geographical.
+ # Geographic.
#
'1204', # Bolton
- '1224', # Aberdeen
+ '1208', # Bodmin
+ '1254', # Blackburn
+ '1276', # Camberley
+ '1297', # Axminster
+ '1298', # Buxton
+ '1363', # Crediton
+ '1364', # Ashburton
+ '1384', # Dudley
+ '1386', # Evesham
+ '1404', # Honiton
+ '1420', # Alton
+ '1460', # Chard
+ '1461', # Gretna
+ '1480', # Huntingdon
+ '1488', # Hungerford
+ '1524', # Lancaster (Mixed area)
+ '1527', # Redditch
+ '1562', # Kidderminster
+ '1566', # Launceston
+ '1606', # Northwich
+ '1629', # Matlock
+ '1635', # Newbury
+ '1647', # Moretonhampstead
+ '1659', # Sanquhar
+ '1695', # Skelmersdale
+ '1726', # St Austell
+ '1744', # St Helens
+ '1750', # Selkirk
+ '1768', # Penrith (Mixed area)
+ '1827', # Tamworth
+ '1837', # Okehampton
+ '1884', # Tiverton
+ '1900', # Workington
+ '1905', # Worcester
+ '1935', # Yeovil
+ '1946', # Whitehaven (Mixed area)
+ '1949', # Whatton
+ '1963', # Wincanton
+ '1995', # Garstang
+
+ # Geographic.
+ #
+ '1224', # Aberdeen
'1244', # Chester
'1382', # Dundee
'1429', # Hartlepool
'1482', # Hull
- '1527', # Redditch
'1582', # Luton
'1670', # Morpeth
'1730', # Petersfield
'1736', # Penzance
- '1750', # Selkirk
'1772', # Preston
'1853', # Ullapool
- '1900', # Workington
- '1946', # Whitehaven
'1947', # Whitby
+ # and 500 others
+
# Mobile.
#
('7400'..'7599').to_a,
'7624',
('7700'..'7999').to_a,
- # Geographical.
+
+ # Geographic.
#
'13873', # Langholm
'15242', # Hornby
@@ -95,7 +175,7 @@
'15396', # Sedbergh
'16973', # Wigton
'16974', # Raughton Head
- '16977', # Brampton[3][4]
+ '16977', # Brampton
'17683', # Appleby
'17684', # Pooley Bridge
'17687', # Keswick
@@ -230,15 +230,26 @@
Phony.split('256464441234').should == ['256', '464', '441234'] # Mubende
end
it 'handles UK numbers' do
- Phony.split('442045671113').should == ['44', '20', '4567', '1113'] # London
- Phony.split('442076229901').should == ['44', '20', '7622', '9901'] # Cardiff
- Phony.split('441136770011').should == ['44', '113', '677', '0011'] # Leeds
+ Phony.split('442075671113').should == ['44', '20', '7567', '1113'] # London
+ Phony.split('442920229901').should == ['44', '29', '2022', '9901'] # Cardiff
+ Phony.split('441134770011').should == ['44', '113', '477', '0011'] # Leeds
+ Phony.split('441412770011').should == ['44', '141', '277', '0011'] # Glasgow
Phony.split('441382229845').should == ['44', '1382', '229845'] # Dundee
- Phony.split('44120499532').should == ['44', '1204', '99532'] # Bolten
- Phony.split('441539618756').should == ['44', '15396', '18756'] # Sedbergh
+ Phony.split('441204500532').should == ['44', '1204', '500532'] # Bolton
+ Phony.split('44120462532').should == ['44', '1204', '62532'] # Bolton
+ Phony.split('441539648756').should == ['44', '15396', '48756'] # Sedbergh
+ Phony.split('441697744555').should == ['44', '16977', '44555'] # Brampton
+ Phony.split('44169772333').should == ['44', '16977', '2333'] # Brampton
+ Phony.split('443005878323').should == ['44', '300', '587', '8323'] # Non-geographic
+ Phony.split('44500557788').should == ['44', '500', '557788'] # Freefone
+ Phony.split('445575671113').should == ['44', '55', '7567', '1113'] # Corporate
+ Phony.split('445644775533').should == ['44', '56', '4477', '5533'] # LIECS/VoIP
+ Phony.split('447020229901').should == ['44', '70', '2022', '9901'] # Personal numbers
Phony.split('447780605207').should == ['44', '7780', '605207'] # Mobile
Phony.split('447480605207').should == ['44', '7480', '605207'] # Mobile
- Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Service, regression
+ Phony.split('44800557788').should == ['44', '800', '557788'] # Freefone
+ Phony.split('448004682355').should == ['44', '808', '468', '2355'] # Freefone
+ Phony.split('448005878323').should == ['44', '800', '587', '8323'] # Freefone, regression
end
it 'handles US numbers' do
Phony.split('15551115511').should == ['1', '555', '111', '5511']

0 comments on commit dc8cc17

Please sign in to comment.