phony 1.2.11 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/lib/countries.rb +385 -0
- data/lib/phony.rb +11 -9
- data/lib/phony/countries.rb +1 -0
- data/lib/phony/countries/austria.rb +68 -67
- data/lib/phony/countries/belgium.rb +29 -57
- data/lib/phony/countries/chile.rb +5 -12
- data/lib/phony/countries/china.rb +21 -20
- data/lib/phony/countries/egypt.rb +12 -37
- data/lib/phony/countries/germany.rb +39 -36
- data/lib/phony/countries/greece.rb +21 -25
- data/lib/phony/countries/hungary.rb +6 -19
- data/lib/phony/countries/italy.rb +174 -152
- data/lib/phony/countries/malaysia.rb +17 -17
- data/lib/phony/countries/netherlands.rb +50 -52
- data/lib/phony/countries/romania.rb +28 -27
- data/lib/phony/countries/south_korea.rb +11 -11
- data/lib/phony/countries/sweden.rb +49 -49
- data/lib/phony/countries/united_kingdom.rb +4 -4
- data/lib/phony/country.rb +14 -80
- data/lib/phony/country_codes.rb +23 -3
- data/lib/phony/dsl.rb +78 -0
- data/lib/phony/national_code.rb +2 -5
- data/lib/phony/national_splitters/dsl.rb +20 -0
- data/lib/phony/national_splitters/fixed.rb +1 -1
- data/lib/phony/national_splitters/none.rb +1 -1
- data/lib/phony/national_splitters/regex.rb +49 -0
- data/lib/phony/national_splitters/variable.rb +6 -6
- data/lib/phony/vanity.rb +3 -0
- data/spec/lib/phony/country_codes_spec.rb +1 -1
- data/spec/lib/phony/country_spec.rb +12 -45
- data/spec/lib/phony/local_splitters/fixed_spec.rb +8 -0
- data/spec/lib/phony/national_code_spec.rb +13 -0
- data/spec/lib/phony/national_splitters/regex_spec.rb +23 -0
- data/spec/lib/phony/national_splitters/variable_spec.rb +2 -4
- data/spec/lib/phony_spec.rb +44 -4
- metadata +9 -21
- data/lib/phony/countries/all_other.rb +0 -455
- data/lib/phony/countries/norway.rb +0 -11
- data/lib/phony/countries/peru.rb +0 -19
- data/lib/phony/countries/portugal.rb +0 -16
- data/lib/phony/national_splitters/experimental.rb +0 -17
- data/spec/lib/phony/countries/austria_spec.rb +0 -24
- data/spec/lib/phony/countries/belgium_spec.rb +0 -33
- data/spec/lib/phony/countries/egypt_spec.rb +0 -18
- data/spec/lib/phony/countries/greece_spec.rb +0 -18
- data/spec/lib/phony/countries/portugal_spec.rb +0 -21
- data/spec/lib/phony/countries/switzerland_spec.rb +0 -18
- data/spec/lib/phony/countries/united_kingdom_spec.rb +0 -50
@@ -3,55 +3,53 @@
|
|
3
3
|
# Note: The netherlands use a variable ndc format from length 2 to 3.
|
4
4
|
# To save space, we only use ndcs of length 2 (and use the fallback of 3 to handle the rest).
|
5
5
|
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
]
|
57
|
-
}
|
6
|
+
ndcs = [
|
7
|
+
'10', # Rotterdam
|
8
|
+
'13', # Tilburg
|
9
|
+
'14', # KPN
|
10
|
+
'15', # Delft
|
11
|
+
'20', # Amsterdam
|
12
|
+
'23', # Haarlem
|
13
|
+
'24', # Nijmegen
|
14
|
+
'26', # Arnhem
|
15
|
+
'30', # Utrecht
|
16
|
+
'33', # Amersfoort
|
17
|
+
'35', # Hilversum
|
18
|
+
'36', # Almere
|
19
|
+
'38', # Zwolle
|
20
|
+
'40', # Eindhoven
|
21
|
+
'43', # Maastricht
|
22
|
+
'45', # Heerlen
|
23
|
+
'46', # Sittard
|
24
|
+
'50', # Groningen
|
25
|
+
'53', # Enschede
|
26
|
+
'55', # Apeldoorn
|
27
|
+
'58', # Leeuwarden
|
28
|
+
'70', # Den Haag
|
29
|
+
'71', # Leiden
|
30
|
+
'72', # Alkmaar
|
31
|
+
'73', # 's-Hertogenbosch
|
32
|
+
'74', # Hengelo
|
33
|
+
'75', # Zaanstad
|
34
|
+
'76', # Breda
|
35
|
+
'77', # Venlo
|
36
|
+
'78', # Dordrecht
|
37
|
+
'79', # Zoetermeer
|
38
|
+
]
|
39
|
+
|
40
|
+
service = [
|
41
|
+
'84', # Persoonlijke-assistentdiensten, zoals voicemail en faxmail
|
42
|
+
'85', # Plaatsonafhankelijk netnummer
|
43
|
+
'87', # Both of the above.
|
44
|
+
'88', # Bedrijfsnummers
|
45
|
+
'91', # Plaatsonafhankelijk netnummer
|
46
|
+
'676', # Inbelnummers van Internetproviders
|
47
|
+
'800', # Gratis informatienummers
|
48
|
+
'900', # Betaalde informatienummers
|
49
|
+
'906', # Betaalde informatienummers
|
50
|
+
'909', # Betaalde informatienummers
|
51
|
+
]
|
52
|
+
|
53
|
+
Phony::Countries::Netherlands = one_of(service) >> split(3,3) |
|
54
|
+
one_of(['6'] + ndcs, :max_length => 3) >> split(8) # mobile + landline
|
55
|
+
# 8 is for mobile numbers, other numbers will work as well (they use 7).
|
@@ -1,31 +1,32 @@
|
|
1
|
+
include Phony::DSL
|
2
|
+
|
1
3
|
# Romanian phone numbers.
|
2
4
|
#
|
3
5
|
# http://en.wikipedia.org/wiki/Romania_telephone_area_codes
|
4
6
|
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
7
|
+
|
8
|
+
ndcs = [
|
9
|
+
'21', # Bucureşti
|
10
|
+
'31', # Bucureşti
|
11
|
+
]
|
12
|
+
mobile = [
|
13
|
+
'71',
|
14
|
+
'72',
|
15
|
+
'73',
|
16
|
+
'74',
|
17
|
+
'75',
|
18
|
+
'76',
|
19
|
+
'77',
|
20
|
+
'78',
|
21
|
+
]
|
22
|
+
service = [
|
23
|
+
'112',
|
24
|
+
'800',
|
25
|
+
'900',
|
26
|
+
'903',
|
27
|
+
'906',
|
28
|
+
]
|
29
|
+
|
30
|
+
Phony::Countries::Romania = one_of(*service) >> split(3,3) |
|
31
|
+
match(/^(7[1-8])\d*$/) >> split(3,4) |
|
32
|
+
one_of('21', '31', :max_length => 3) >> split(3,4) # Bucureşti
|
@@ -1,15 +1,15 @@
|
|
1
|
+
include Phony::DSL
|
2
|
+
|
1
3
|
# South Korean (Republic of Korea) phone numbers.
|
2
4
|
#
|
3
5
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_South_Korea
|
4
6
|
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:service => %w{ 30 50 60 70 80 100 101 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 125 127 128 129 131 132 134 141 182 188 }
|
15
|
-
}
|
7
|
+
|
8
|
+
# TODO 4-digit services, like "unreasonable infringement of livelihood report" number :)
|
9
|
+
#
|
10
|
+
service = %w{ 30 50 60 70 80 100 101 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 125 127 128 129 131 132 134 141 182 188 }
|
11
|
+
mobile = ('10'..'19').to_a
|
12
|
+
|
13
|
+
Phony::Countries::SouthKorea = one_of(*service) >> split(3,3) |
|
14
|
+
one_of(*mobile) >> split(4,4) |
|
15
|
+
one_of('2', :max_length => 2) >> split(4,4) # Seoul
|
@@ -6,52 +6,52 @@
|
|
6
6
|
# Taken from: http://en.wikipedia.org/wiki/Telephone_numbers_in_Sweden
|
7
7
|
# http://www.pts.se/upload/Ovrigt/Tele/Nummerfragor/bilaga-2b.pdf
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
9
|
+
|
10
|
+
ndcs = [
|
11
|
+
'7', # Non-geographical
|
12
|
+
'8', # Stockholm
|
13
|
+
'10', # VOIP
|
14
|
+
'11', # Norrköping
|
15
|
+
'13', # Linköping
|
16
|
+
'16', # Eskilstuna-Torshälla
|
17
|
+
'18', # Uppsala
|
18
|
+
'19', # Örebro-Kumla
|
19
|
+
'20', # toll-free
|
20
|
+
'21', # Västerås
|
21
|
+
'23', # Falun
|
22
|
+
'26', # Gävle-Sandviken
|
23
|
+
'31', # Göteborg
|
24
|
+
'33', # Borås
|
25
|
+
'35', # Halmstad
|
26
|
+
'36', # Jönköping-Huskvarna
|
27
|
+
'40', # Malmö
|
28
|
+
'42', # Helsingborg-Höganäs
|
29
|
+
'44', # Kristianstad
|
30
|
+
'46', # Lund
|
31
|
+
'54', # Karlstad
|
32
|
+
'60', # Sundsvall-Timrå
|
33
|
+
'63', # Östersund
|
34
|
+
'90', # Umeå
|
35
|
+
]
|
36
|
+
mobile = [
|
37
|
+
'70', # Mobile
|
38
|
+
'71', # Telematics
|
39
|
+
'72', # Mobile
|
40
|
+
'73', # Mobile
|
41
|
+
'74', # Pagers
|
42
|
+
'76', # Mobile
|
43
|
+
]
|
44
|
+
service = [
|
45
|
+
'99', # Premium Rate
|
46
|
+
'112', # Emergency Service
|
47
|
+
'116', # Psychological Help
|
48
|
+
'118', # Number enquiries
|
49
|
+
'900', # Premium Rate
|
50
|
+
'939', # Premium Rate
|
51
|
+
'944', # Premium Rate
|
52
|
+
'1177', # Health Care Advice
|
53
|
+
'11414', # Police
|
54
|
+
]
|
55
|
+
|
56
|
+
Phony::Countries::Sweden = one_of(service) >> split(3,3) |
|
57
|
+
one_of(ndcs + mobile, :max_length => 3) >> split(8)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
#
|
13
13
|
handlers = []
|
14
14
|
|
15
|
-
area_code_2_national = Phony::NationalSplitters::Variable.new nil,
|
15
|
+
area_code_2_national = Phony::NationalSplitters::Variable.new nil, [
|
16
16
|
'20', # London
|
17
17
|
'23', # Southampton, Portsmith
|
18
18
|
'24', # Coventry
|
@@ -22,7 +22,7 @@ area_code_2_national = Phony::NationalSplitters::Variable.new nil, :landline =>
|
|
22
22
|
area_code_2_local = Phony::LocalSplitters::Fixed.instance_for [4, 4]
|
23
23
|
handlers << Phony::NationalCode.new(area_code_2_national, area_code_2_local)
|
24
24
|
|
25
|
-
area_code_3_national = Phony::NationalSplitters::Variable.new nil,
|
25
|
+
area_code_3_national = Phony::NationalSplitters::Variable.new nil, [
|
26
26
|
# Geographical.
|
27
27
|
#
|
28
28
|
'113', # Leeds
|
@@ -61,7 +61,7 @@ handlers << Phony::NationalCode.new(area_code_3_national, area_code_3
|
|
61
61
|
|
62
62
|
# 6 is the fallback length.
|
63
63
|
#
|
64
|
-
area_code_45_national = Phony::NationalSplitters::Variable.new 6,
|
64
|
+
area_code_45_national = Phony::NationalSplitters::Variable.new 6, [
|
65
65
|
# Geographical.
|
66
66
|
#
|
67
67
|
'1204', # Bolton
|
@@ -100,7 +100,7 @@ area_code_45_national = Phony::NationalSplitters::Variable.new 6, :landline => [
|
|
100
100
|
'17684', # Pooley Bridge
|
101
101
|
'17687', # Keswick
|
102
102
|
'19467', # Gosforth
|
103
|
-
]
|
103
|
+
].flatten
|
104
104
|
area_code_45_local = Phony::LocalSplitters::Fixed.instance_for [6]
|
105
105
|
handlers << Phony::NationalCode.new(area_code_45_national, area_code_45_local)
|
106
106
|
|
data/lib/phony/country.rb
CHANGED
@@ -4,18 +4,31 @@ module Phony
|
|
4
4
|
#
|
5
5
|
class Country
|
6
6
|
|
7
|
+
attr_accessor :codes
|
8
|
+
|
7
9
|
#
|
8
10
|
#
|
9
11
|
def initialize *codes
|
10
12
|
@codes = codes
|
11
13
|
end
|
12
14
|
|
15
|
+
# DSL.
|
16
|
+
#
|
17
|
+
# TODO
|
18
|
+
#
|
19
|
+
def |(other)
|
20
|
+
self.codes = self.codes + other.codes
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
13
24
|
# A number is split with the code handlers as given in the initializer.
|
14
25
|
#
|
26
|
+
# Note: If the ndc is nil, it will not return it.
|
27
|
+
#
|
15
28
|
def split national_number
|
16
29
|
@codes.each do |code|
|
17
30
|
ndc, *rest = code.split national_number
|
18
|
-
return [ndc, *rest] if rest && !rest.empty?
|
31
|
+
return ndc ? [ndc, *rest] : rest if rest && !rest.empty?
|
19
32
|
end
|
20
33
|
end
|
21
34
|
|
@@ -46,85 +59,6 @@ module Phony
|
|
46
59
|
"#{ndc}#{Vanity.replace(rest.join)}"
|
47
60
|
end
|
48
61
|
|
49
|
-
|
50
|
-
# Get a configured country instance.
|
51
|
-
#
|
52
|
-
# Define your countries like this:
|
53
|
-
# Phony::Countries::Austria = Phony::Country.configured <options>
|
54
|
-
#
|
55
|
-
# Example:
|
56
|
-
# Phony::Country.configured :local_format => [3, 2, 2],
|
57
|
-
# :service_local_format => [3, 3],
|
58
|
-
# :ndc_fallback_length => 4,
|
59
|
-
# :ndc_mapping => {
|
60
|
-
# :normal => ['44'],
|
61
|
-
# :service => ['800'],
|
62
|
-
# :mobile => ['76']
|
63
|
-
# }
|
64
|
-
#
|
65
|
-
# Service numbers can have a special formatting.
|
66
|
-
# Cellphones usually use the same as the landline.
|
67
|
-
# If that is not the case, I will expand the framework.
|
68
|
-
#
|
69
|
-
def self.configured options = {}
|
70
|
-
normalize = options[:normalize]
|
71
|
-
ndc_fallback_length = options[:ndc_fallback_length]
|
72
|
-
ndc_mapping = options[:ndc_mapping] || raise("No ndc_mapping given!")
|
73
|
-
|
74
|
-
codes = []
|
75
|
-
|
76
|
-
if ndc_mapping[:service]
|
77
|
-
service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => ndc_mapping[:service]
|
78
|
-
service_local_splitter = Phony::LocalSplitters::Fixed.instance_for options[:service_local_format] || [3, 6]
|
79
|
-
codes << Phony::NationalCode.new(service_national_splitter, service_local_splitter, normalize)
|
80
|
-
end
|
81
|
-
if ndc_mapping[:mobile]
|
82
|
-
mobile_local_format = options[:mobile_local_format] || options[:local_format] || [9]
|
83
|
-
mobile_national_splitter = Phony::NationalSplitters::Variable.new nil, :mobile => ndc_mapping[:mobile]
|
84
|
-
mobile_local_splitter = Phony::LocalSplitters::Fixed.instance_for mobile_local_format
|
85
|
-
codes << Phony::NationalCode.new(mobile_national_splitter, mobile_local_splitter, normalize)
|
86
|
-
end
|
87
|
-
|
88
|
-
national_splitter = Phony::NationalSplitters::Variable.new ndc_fallback_length, ndc_mapping
|
89
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for options[:local_format] || [3, 2, 2]
|
90
|
-
codes << Phony::NationalCode.new(national_splitter, local_splitter, normalize)
|
91
|
-
|
92
|
-
new *codes
|
93
|
-
end
|
94
|
-
|
95
|
-
# Gets a configured country instance with fixed length ndc code.
|
96
|
-
#
|
97
|
-
# Define your countries like this:
|
98
|
-
# Phony::Countries::Switzerland = Phony::Country.fixed <options>
|
99
|
-
#
|
100
|
-
# Example:
|
101
|
-
# Phony::Country.fixed :ndc_length => 4,
|
102
|
-
# :local_format => [3, 2, 2],
|
103
|
-
# :service_local_format => [3, 3],
|
104
|
-
# :service_ndcs => ['800']
|
105
|
-
#
|
106
|
-
def self.fixed options = {}
|
107
|
-
normalize = options[:normalize]
|
108
|
-
ndc_length = options[:ndc_length]
|
109
|
-
service_ndcs = options[:service_ndcs]
|
110
|
-
local_format = options[:local_format]
|
111
|
-
|
112
|
-
codes = []
|
113
|
-
|
114
|
-
if service_ndcs
|
115
|
-
service_local_format = options[:service_local_format] || local_format || [3, 3]
|
116
|
-
service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => service_ndcs
|
117
|
-
service_local_splitter = Phony::LocalSplitters::Fixed.instance_for service_local_format
|
118
|
-
codes << Phony::NationalCode.new(service_national_splitter, service_local_splitter, normalize)
|
119
|
-
end
|
120
|
-
|
121
|
-
national_splitter = Phony::NationalSplitters::Fixed.new ndc_length
|
122
|
-
local_splitter = Phony::LocalSplitters::Fixed.instance_for local_format || [3, 2, 2]
|
123
|
-
codes << Phony::NationalCode.new(national_splitter, local_splitter, normalize)
|
124
|
-
|
125
|
-
new *codes
|
126
|
-
end
|
127
|
-
|
128
62
|
end
|
129
63
|
|
130
64
|
end
|