phony 1.6.2 → 1.6.3
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.
- data/lib/phony.rb +1 -0
- data/lib/phony/countries.rb +3 -1
- data/lib/phony/countries/ireland.rb +76 -0
- data/spec/lib/phony/countries_spec.rb +9 -0
- data/spec/lib/phony/country_codes_spec.rb +6 -0
- metadata +3 -2
data/lib/phony.rb
CHANGED
@@ -21,6 +21,7 @@ require File.expand_path '../phony/dsl', __FILE__
|
|
21
21
|
require File.expand_path '../phony/countries/austria', __FILE__
|
22
22
|
require File.expand_path '../phony/countries/china', __FILE__
|
23
23
|
require File.expand_path '../phony/countries/germany', __FILE__
|
24
|
+
require File.expand_path '../phony/countries/ireland', __FILE__
|
24
25
|
require File.expand_path '../phony/countries/italy', __FILE__
|
25
26
|
require File.expand_path '../phony/countries/malaysia', __FILE__
|
26
27
|
require File.expand_path '../phony/countries/netherlands', __FILE__
|
data/lib/phony/countries.rb
CHANGED
@@ -310,7 +310,9 @@ Phony.define do
|
|
310
310
|
fixed(3) >> split(3,4) # 3-digit NDCs
|
311
311
|
|
312
312
|
country '352', todo # Luxembourg
|
313
|
-
|
313
|
+
|
314
|
+
# country '353' # Republic of Ireland, see special file.
|
315
|
+
|
314
316
|
country '354', none >> split(3,4) # Iceland
|
315
317
|
country '355', todo # Albania
|
316
318
|
country '356', todo # Malta
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# The Republic of Ireland has variable-length NDCs from 2-3 digits in length. Depending on the NDC, the length of the subscriber number varies from 5-7 characters in length. There does not appear to be any pattern that relates NDCs to subscriber number length.
|
2
|
+
#
|
3
|
+
# 7 digit subscriber numbers follow a 3-4 split pattern.
|
4
|
+
# 5 and 6 digit subscriber numbers appear split in some examples, and not in others; to be conservative, these are not currently split.
|
5
|
+
#
|
6
|
+
# For NDCs that are not recognized, we fall back to not attempting to split out an NDC at all.
|
7
|
+
#
|
8
|
+
# References:
|
9
|
+
# http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf
|
10
|
+
# http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Republic_of_Ireland
|
11
|
+
#
|
12
|
+
handlers = []
|
13
|
+
|
14
|
+
ndcs_with_5_subscriber_digits = [
|
15
|
+
('22'..'29').to_a, # Mallow, Bandon, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
|
16
|
+
'402', # Arklow
|
17
|
+
'404', # Wicklow
|
18
|
+
'43', # Longford, Granard
|
19
|
+
'44', # Mullingar, Castlepollard, Tyrellspass
|
20
|
+
'47', # Monaghan, Clones
|
21
|
+
'48', # Northern Ireland
|
22
|
+
'502', # Portlaoise, Abbeyleix
|
23
|
+
'504', # Thurles
|
24
|
+
'505', # Roscrea
|
25
|
+
'506', # Tullamore
|
26
|
+
'509', # Bin-
|
27
|
+
('52'..'55').to_a, # Killenaule, Wexford, Enniscorthy, Ferns, Gorey
|
28
|
+
'62', # Tipperary, Cashel
|
29
|
+
'63', # Charleville
|
30
|
+
'64', # Killarney, Rathmore
|
31
|
+
'67', # Nenagh
|
32
|
+
'68', # Listowel
|
33
|
+
'69', # Newcastle West
|
34
|
+
'76', # VoIP
|
35
|
+
'93', # Tuam
|
36
|
+
('94'..'99').to_a # Castlebar, Castlerea, Claremorris, Clifden, Ballina, Belmullet, Westport, Kilronan
|
37
|
+
].flatten
|
38
|
+
|
39
|
+
ndcs_with_6_subscriber_digits = [
|
40
|
+
'45', # Naas, Kildare, Curragh
|
41
|
+
'51', # Waterford, Carrick-on-Suir, New Ross, Kilmacthomas
|
42
|
+
'61', # Limerick, Scariff
|
43
|
+
'91', # Galway, GOrt, Loughrea
|
44
|
+
]
|
45
|
+
|
46
|
+
ndcs_with_7_subscriber_digits = [
|
47
|
+
'1', # Dublin
|
48
|
+
'21', # Cork, Coachford, Kinsale
|
49
|
+
'41', # Ardee
|
50
|
+
'42', # Dundalk, Carrickmacross, Castleblaney
|
51
|
+
'46', # Navan, Kells, Trim, Enfield, Edenderry
|
52
|
+
'49', # Cavan, Cootehill, Oldcastle, Belturbet
|
53
|
+
'56', # Kilkenny, Castlecomer
|
54
|
+
'58', # Dungarvan
|
55
|
+
'59', # Carlow, Muine Bheag, Athy, Baltinglass
|
56
|
+
'65', # Ennistymon, Kilrush
|
57
|
+
'66', # Tralee, Dingle, Killorglin, Cahirciveen
|
58
|
+
'71', # Sligo, Manorhamilton, Carrick-on-Shannon
|
59
|
+
'74', # Donegal, Letterkenny, Dungloe, Buncrana
|
60
|
+
'90', # Athlone, Ballinasloe, Portumna, Roscommon
|
61
|
+
'94' # Ballinrobe
|
62
|
+
]
|
63
|
+
|
64
|
+
freefone = [
|
65
|
+
'800'
|
66
|
+
]
|
67
|
+
|
68
|
+
Phony.define do
|
69
|
+
country '353', one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
|
70
|
+
one_of(ndcs_with_5_subscriber_digits) >> split(5) |
|
71
|
+
one_of(ndcs_with_6_subscriber_digits) >> split(6) |
|
72
|
+
one_of(freefone) >> split(6) |
|
73
|
+
match(/^(8\d).+$/) >> split(3,4) | # mobile
|
74
|
+
none >> split(0)
|
75
|
+
|
76
|
+
end
|
@@ -111,6 +111,15 @@ describe 'country descriptions' do
|
|
111
111
|
Phony.split('3544621234').should == ['354', '462', '1234'] # Akureyri
|
112
112
|
Phony.split('3545511234').should == ['354', '551', '1234'] # Reykjavík
|
113
113
|
end
|
114
|
+
it 'handles irish numbers' do
|
115
|
+
Phony.split('35311234567').should == ['353', '1', '123', '4567'] # Dublin, 7 digit subscriber #
|
116
|
+
Phony.split('3532212345').should == ['353', '22', '12345'] # Mallow, 5 digit subscriber #
|
117
|
+
Phony.split('35345123456').should == ['353', '45', '123456'] # Naas, 6 digit subscriber #
|
118
|
+
Phony.split('353801234567').should == ['353', '80', '123', '4567'] # Mobile
|
119
|
+
Phony.split('3537612345').should == ['353', '76', '12345'] # VoIP
|
120
|
+
Phony.split('353800123456').should == ['353', '800', '123456'] # Freefone
|
121
|
+
Phony.split('353000123456').should == ['353', '000123456'] # No NDC/local split for unrecognized
|
122
|
+
end
|
114
123
|
it 'handles italian numbers' do
|
115
124
|
Phony.split('3934869528').should == ['39', '3486', '952', '8'] # Mobile
|
116
125
|
Phony.split('390612341234').should == ['39', '06', '1234', '1234'] # Roma
|
@@ -75,6 +75,9 @@ describe Phony::CountryCodes do
|
|
75
75
|
it "should format american numbers" do
|
76
76
|
@countries.formatted('18705551122').should == '+1 870 555 1122'
|
77
77
|
end
|
78
|
+
it "should format irish numbers" do
|
79
|
+
@countries.formatted('35311234567').should == '+353 1 123 4567'
|
80
|
+
end
|
78
81
|
end
|
79
82
|
describe "international" do
|
80
83
|
it "should format north american numbers" do
|
@@ -95,6 +98,9 @@ describe Phony::CountryCodes do
|
|
95
98
|
it 'should format liechtensteiner numbers' do
|
96
99
|
@countries.formatted('4233841148', :format => :international_relative).should == '00423 384 11 48'
|
97
100
|
end
|
101
|
+
it "should format irish numbers" do
|
102
|
+
@countries.formatted('35311234567', :format => :international).should == '+353 1 123 4567'
|
103
|
+
end
|
98
104
|
context 'with no spaces' do
|
99
105
|
it "should format north american numbers" do
|
100
106
|
Phony.formatted('18091231234', :format => :international, :spaces => '').should == '+18091231234'
|
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.6.
|
4
|
+
version: 1.6.3
|
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-
|
12
|
+
date: 2012-02-27 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
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- lib/phony/countries/austria.rb
|
24
24
|
- lib/phony/countries/china.rb
|
25
25
|
- lib/phony/countries/germany.rb
|
26
|
+
- lib/phony/countries/ireland.rb
|
26
27
|
- lib/phony/countries/italy.rb
|
27
28
|
- lib/phony/countries/malaysia.rb
|
28
29
|
- lib/phony/countries/netherlands.rb
|