Browse files

Fixes for 5+4 and 5+5 numbers. Combined the rules for 500 and 800 3+6…

… numbers. Additional comments and clarifications.
  • Loading branch information...
1 parent 127ca26 commit cf5b12361e346191bcfeb486c06d3a00a1c5b522 @g1smd g1smd committed Aug 24, 2012
Showing with 58 additions and 47 deletions.
  1. +58 −47 lib/phony/countries/united_kingdom.rb
View
105 lib/phony/countries/united_kingdom.rb
@@ -8,27 +8,33 @@
# a 3-3-4 or 3-6 formatting rule with area codes that are 3 digits long,
# a 4-6 or 4-5 formatting rule with area codes that are 4 digits long, and
# a 5-5 or 5-4 formatting rule with area codes that are 5 digits long.
-# There can be a mix of number lengths within a single area code.
+# There can be a mix of number lengths within a single area code.
#
two_digit_ndc = [
- # Geographic.
+ # Geographic [2+8].
#
'20', # London
'23', # Southampton, Portsmith
'24', # Coventry
'28', # Northern Ireland
'29', # Cardiff
- # Non-geographic.
+ # Non-geographic [2+8].
#
'55', # Corporate
'56', # LIECS/VoIP
'70', # Personal numbers
]
+# three_digit_ndc_with_nine_digits
+ # Non-geographic [3+6].
+ #
+ # '500', # Freephone (9 digits) handled in specific rule, see below.
+ # '800', # Freephone (9 digits) handled in specific rule, see below.
+
three_digit_ndc = [
- # Geographic.
+ # Geographic [3+7].
#
'113', # Leeds
'114', # Sheffield
@@ -43,7 +49,7 @@
'161', # Manchester
'191', # Tyne and Wear/County Durham
- # Services.
+ # Services [3+7].
#
'300', # Non-geographic charged at same rate as 01
'301',
@@ -68,17 +74,17 @@
'800', # Freephone (10 digits) # 9 digits handled in specific rule, see below.
'808', # Freephone (10 digits)
- '842', # Business rate
+ '842', # Business rate [3+7].
'843',
'844',
'845',
'870',
- '871', # Premium rate
+ '871', # Premium rate [3+7].
'872',
'873',
- '900', # Premium rate content services
+ '900', # Premium rate content services [3+7].
'901',
'902',
'903',
@@ -87,19 +93,38 @@
'906',
'907',
- '908', # Sexual entertainment services
- '909', # Sexual entertainment services
- '982', # Sexual entertainment services
+ '908', # Sexual entertainment services [3+7].
+ '909',
+ '982',
]
-# 6 is the fallback length.
-#
-no_split = [
- # Non-geographic.
+# five_digit_ndc_with_nine_digits
+ # Geographic [5+4].
#
- '500', # Freephone (9 digits)
+ # '16977', # Brampton (contains both 4 and 5 digit numbers)
+ # # 9 digits handled in specific rule, see below.
- # Geographic.
+five_digit_ndc = [
+ # Geographic [5+5].
+ #
+ # These areas use 5-5 format. One area has some 5-4 numbers too (see above).
+ # They share their initial digits with area codes using 4-6 (and 4-5).
+ '13873', # Langholm
+ '15242', # Hornby
+ '15394', # Hawkshead
+ '15395', # Grange-over-Sands
+ '15396', # Sedbergh
+ '16973', # Wigton
+ '16974', # Raughton Head
+ '16977', # Brampton (contains both 4 and 5 digit numbers)
+ '17683', # Appleby
+ '17684', # Pooley Bridge
+ '17687', # Keswick
+ '19467', # Gosforth
+]
+
+no_split = [
+ # Geographic [4+6]/[4+5].
#
# These 40 area codes have a mix of 4-6 and 4-5 numbers
# The three 'mixed' areas also have part of their number
@@ -145,7 +170,15 @@
'1963', # Wincanton
'1995', # Garstang
- # Geographic.
+# 6 is the fallback length.
+#
+ # Mobile [4+6].
+ #
+ ('7400'..'7599').to_a,
+ '7624',
+ ('7700'..'7999').to_a,
+
+ # Geographic [4+6].
#
# About 500 area codes use the 4-6 format
# The three 'mixed' areas also have part of their number
@@ -166,36 +199,14 @@
'1853', # Ullapool
'1947', # Whitby
# and 500 others
-
- # Mobile.
- #
- ('7400'..'7599').to_a,
- '7624',
- ('7700'..'7999').to_a,
-
- # Geographic.
- #
- # Note: Removed and replaced by a catchall (fixed(5), see below).
- # These areas use 5-5 format. One area has some 5-4 numbers too.
- # They share their initial digits with area codes using 4-6 (and 4-5).
- # '13873', # Langholm
- # '15242', # Hornby
- # '15394', # Hawkshead
- # '15395', # Grange-over-Sands
- # '15396', # Sedbergh
- # '16973', # Wigton
- # '16974', # Raughton Head
- # '16977', # Brampton
- # '17683', # Appleby
- # '17684', # Pooley Bridge
- # '17687', # Keswick
- # '19467', # Gosforth
].flatten
Phony.define do
- country '44', one_of(two_digit_ndc) >> split(4,4) | # 2-4-4
- match(/^(800)\d{6}$/) >> split(6) | # Special handling for 800 + 6 numbers.
- one_of(three_digit_ndc) >> split(3,4) | # 3-3-4
- one_of(no_split) >> split(6) | # 500 / 3-6
- fixed(5) >> split(5) # Catch all for 5-5 numbers.
+ country '44', one_of(two_digit_ndc) >> split(4,4) | # 2-4-4
+ match(/^([58]00)\d{6}$/) >> split(6) | # Special handling for 500 and 800: 3-6 numbers.
+ one_of(three_digit_ndc) >> split(3,4) | # 3-3-4
+ match(/^(16977)\d{4}$/) >> split(4) | # Special handling for 16977: 5-4 numbers.
+ one_of(five_digit_ndc) >> split(5) | # 5-5
+ one_of(no_split) >> split(6) | # 4-6 and 4-5
+ fixed(4) >> split(6) # Catchall for 4-6 numbers.
end

0 comments on commit cf5b123

Please sign in to comment.