phony 2.18.3 → 3.0.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.
- checksums.yaml +4 -4
- data/README.md +117 -0
- data/lib/phony/config.rb +25 -26
- data/lib/phony/countries/argentina.rb +352 -0
- data/lib/phony/countries/austria.rb +73 -74
- data/lib/phony/countries/bangladesh.rb +27 -28
- data/lib/phony/countries/belarus.rb +110 -111
- data/lib/phony/countries/brazil.rb +93 -93
- data/lib/phony/countries/cambodia.rb +10 -14
- data/lib/phony/countries/china.rb +22 -18
- data/lib/phony/countries/croatia.rb +6 -5
- data/lib/phony/countries/georgia.rb +84 -84
- data/lib/phony/countries/germany.rb +4067 -4068
- data/lib/phony/countries/guinea.rb +8 -8
- data/lib/phony/countries/india.rb +31 -34
- data/lib/phony/countries/indonesia.rb +57 -46
- data/lib/phony/countries/ireland.rb +10 -9
- data/lib/phony/countries/italy.rb +79 -60
- data/lib/phony/countries/japan.rb +456 -406
- data/lib/phony/countries/kyrgyzstan.rb +109 -109
- data/lib/phony/countries/latvia.rb +34 -34
- data/lib/phony/countries/libya.rb +109 -107
- data/lib/phony/countries/malaysia.rb +12 -12
- data/lib/phony/countries/moldova.rb +42 -42
- data/lib/phony/countries/montenegro.rb +24 -20
- data/lib/phony/countries/myanmar.rb +39 -39
- data/lib/phony/countries/namibia.rb +35 -29
- data/lib/phony/countries/nepal.rb +60 -62
- data/lib/phony/countries/netherlands.rb +13 -13
- data/lib/phony/countries/pakistan.rb +135 -111
- data/lib/phony/countries/paraguay.rb +135 -135
- data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +125 -128
- data/lib/phony/countries/saudi_arabia.rb +5 -5
- data/lib/phony/countries/serbia.rb +48 -36
- data/lib/phony/countries/somalia.rb +18 -18
- data/lib/phony/countries/south_korea.rb +16 -13
- data/lib/phony/countries/sweden.rb +356 -48
- data/lib/phony/countries/taiwan.rb +20 -18
- data/lib/phony/countries/tajikistan.rb +70 -70
- data/lib/phony/countries/turkmenistan.rb +65 -65
- data/lib/phony/countries/ukraine.rb +607 -607
- data/lib/phony/countries/united_kingdom.rb +66 -66
- data/lib/phony/countries/uruguay.rb +40 -41
- data/lib/phony/countries/vietnam.rb +20 -14
- data/lib/phony/countries/zimbabwe.rb +31 -31
- data/lib/phony/countries.rb +509 -453
- data/lib/phony/country.rb +50 -44
- data/lib/phony/country_codes.rb +77 -57
- data/lib/phony/dsl.rb +25 -28
- data/lib/phony/local_splitters/fixed.rb +24 -29
- data/lib/phony/local_splitters/regex.rb +30 -31
- data/lib/phony/national_code.rb +7 -10
- data/lib/phony/national_splitters/default.rb +9 -11
- data/lib/phony/national_splitters/dsl.rb +8 -18
- data/lib/phony/national_splitters/fixed.rb +12 -15
- data/lib/phony/national_splitters/none.rb +8 -14
- data/lib/phony/national_splitters/regex.rb +13 -17
- data/lib/phony/national_splitters/variable.rb +37 -38
- data/lib/phony/trunk_code.rb +23 -23
- data/lib/phony/vanity.rb +12 -13
- data/lib/phony.rb +84 -83
- metadata +14 -45
- data/README.textile +0 -112
- data/spec/functional/config_spec.rb +0 -44
- data/spec/functional/plausibility_spec.rb +0 -608
- data/spec/lib/phony/countries_spec.rb +0 -1391
- data/spec/lib/phony/country_codes_spec.rb +0 -203
- data/spec/lib/phony/country_spec.rb +0 -84
- data/spec/lib/phony/dsl_spec.rb +0 -24
- data/spec/lib/phony/local_splitters/fixed_spec.rb +0 -56
- data/spec/lib/phony/local_splitters/regex_spec.rb +0 -97
- data/spec/lib/phony/national_code_spec.rb +0 -91
- data/spec/lib/phony/national_splitters/default_spec.rb +0 -34
- data/spec/lib/phony/national_splitters/fixed_spec.rb +0 -49
- data/spec/lib/phony/national_splitters/none_spec.rb +0 -28
- data/spec/lib/phony/national_splitters/regex_spec.rb +0 -23
- data/spec/lib/phony/national_splitters/variable_spec.rb +0 -39
- data/spec/lib/phony/vanity_spec.rb +0 -30
- data/spec/lib/phony_spec.rb +0 -70
data/lib/phony/vanity.rb
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Phony
|
|
2
|
-
|
|
3
4
|
# Helper module that maps vanity numbers to digit numbers.
|
|
4
5
|
#
|
|
5
6
|
module Vanity
|
|
6
|
-
|
|
7
7
|
# Returns a char to number mapping string for the String#tr method.
|
|
8
8
|
#
|
|
9
9
|
def self.mapping
|
|
10
|
-
@@mapping ||= [
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
@@mapping ||= %w[
|
|
11
|
+
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
|
12
|
+
2223334445556667777888999922233344455566677778889999
|
|
13
13
|
]
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
# Replaces (and normalizes) vanity characters of passed number with correct digits.
|
|
17
17
|
#
|
|
18
|
-
def self.replace
|
|
18
|
+
def self.replace(number)
|
|
19
19
|
number.tr(*mapping)
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
# Returns true if there is a character in the number
|
|
23
23
|
# after the first three numbers.
|
|
24
24
|
#
|
|
25
25
|
@@vanity_regexp = /\A\d{3}[a-zA-Z]{6,12}\Z/
|
|
26
|
-
def self.vanity?
|
|
26
|
+
def self.vanity?(number)
|
|
27
27
|
!(normalized(number) =~ @@vanity_regexp).nil?
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
# Vanity-Normalized.
|
|
31
31
|
#
|
|
32
32
|
@@vanity_normalizing_regexp = /^0*|[^\w]/
|
|
33
|
-
def self.normalized
|
|
33
|
+
def self.normalized(number)
|
|
34
34
|
number.gsub @@vanity_normalizing_regexp, ''
|
|
35
35
|
end
|
|
36
|
-
|
|
37
36
|
end
|
|
38
|
-
end
|
|
37
|
+
end
|
data/lib/phony.rb
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# NOTE We use Kernel.load here, as it's possible to redefine Phony via Phony::Config.
|
|
3
|
+
# NOTE: We use Kernel.load here, as it's possible to redefine Phony via Phony::Config.
|
|
4
4
|
|
|
5
5
|
# Framework.
|
|
6
6
|
#
|
|
7
|
-
load File.expand_path '
|
|
8
|
-
load File.expand_path '
|
|
9
|
-
load File.expand_path '
|
|
10
|
-
load File.expand_path '
|
|
11
|
-
load File.expand_path '
|
|
12
|
-
load File.expand_path '
|
|
13
|
-
load File.expand_path '
|
|
14
|
-
load File.expand_path '
|
|
15
|
-
load File.expand_path '
|
|
16
|
-
load File.expand_path '
|
|
17
|
-
load File.expand_path '
|
|
18
|
-
load File.expand_path '
|
|
19
|
-
load File.expand_path '
|
|
20
|
-
load File.expand_path '
|
|
21
|
-
load File.expand_path '
|
|
7
|
+
load File.expand_path 'phony/config.rb', __dir__
|
|
8
|
+
load File.expand_path 'phony/vanity.rb', __dir__
|
|
9
|
+
load File.expand_path 'phony/local_splitters/fixed.rb', __dir__
|
|
10
|
+
load File.expand_path 'phony/local_splitters/regex.rb', __dir__
|
|
11
|
+
load File.expand_path 'phony/national_splitters/dsl.rb', __dir__
|
|
12
|
+
load File.expand_path 'phony/national_splitters/fixed.rb', __dir__
|
|
13
|
+
load File.expand_path 'phony/national_splitters/variable.rb', __dir__
|
|
14
|
+
load File.expand_path 'phony/national_splitters/regex.rb', __dir__
|
|
15
|
+
load File.expand_path 'phony/national_splitters/default.rb', __dir__
|
|
16
|
+
load File.expand_path 'phony/national_splitters/none.rb', __dir__
|
|
17
|
+
load File.expand_path 'phony/national_code.rb', __dir__
|
|
18
|
+
load File.expand_path 'phony/country.rb', __dir__
|
|
19
|
+
load File.expand_path 'phony/trunk_code.rb', __dir__
|
|
20
|
+
load File.expand_path 'phony/country_codes.rb', __dir__
|
|
21
|
+
load File.expand_path 'phony/dsl.rb', __dir__
|
|
22
22
|
|
|
23
23
|
# Countries.
|
|
24
24
|
#
|
|
25
25
|
# The ones that need more space to define.
|
|
26
26
|
#
|
|
27
|
-
load File.expand_path '
|
|
28
|
-
load File.expand_path '
|
|
29
|
-
load File.expand_path '
|
|
30
|
-
load File.expand_path '
|
|
31
|
-
load File.expand_path '
|
|
32
|
-
load File.expand_path '
|
|
33
|
-
load File.expand_path '
|
|
34
|
-
load File.expand_path '
|
|
35
|
-
load File.expand_path '
|
|
36
|
-
load File.expand_path '
|
|
37
|
-
load File.expand_path '
|
|
38
|
-
load File.expand_path '
|
|
39
|
-
load File.expand_path '
|
|
40
|
-
load File.expand_path '
|
|
41
|
-
load File.expand_path '
|
|
42
|
-
load File.expand_path '
|
|
43
|
-
load File.expand_path '
|
|
44
|
-
load File.expand_path '
|
|
45
|
-
load File.expand_path '
|
|
46
|
-
load File.expand_path '
|
|
47
|
-
load File.expand_path '
|
|
48
|
-
load File.expand_path '
|
|
49
|
-
load File.expand_path '
|
|
50
|
-
load File.expand_path '
|
|
51
|
-
load File.expand_path '
|
|
52
|
-
load File.expand_path '
|
|
53
|
-
load File.expand_path '
|
|
54
|
-
load File.expand_path '
|
|
55
|
-
load File.expand_path '
|
|
56
|
-
load File.expand_path '
|
|
57
|
-
load File.expand_path '
|
|
58
|
-
load File.expand_path '
|
|
59
|
-
load File.expand_path '
|
|
60
|
-
load File.expand_path '
|
|
61
|
-
load File.expand_path '
|
|
62
|
-
load File.expand_path '
|
|
63
|
-
load File.expand_path '
|
|
64
|
-
load File.expand_path '
|
|
65
|
-
load File.expand_path '
|
|
66
|
-
load File.expand_path '
|
|
67
|
-
load File.expand_path '
|
|
27
|
+
load File.expand_path 'phony/countries/argentina.rb', __dir__
|
|
28
|
+
load File.expand_path 'phony/countries/austria.rb', __dir__
|
|
29
|
+
load File.expand_path 'phony/countries/bangladesh.rb', __dir__
|
|
30
|
+
load File.expand_path 'phony/countries/belarus.rb', __dir__
|
|
31
|
+
load File.expand_path 'phony/countries/brazil.rb', __dir__
|
|
32
|
+
load File.expand_path 'phony/countries/cambodia.rb', __dir__
|
|
33
|
+
load File.expand_path 'phony/countries/croatia.rb', __dir__
|
|
34
|
+
load File.expand_path 'phony/countries/china.rb', __dir__
|
|
35
|
+
load File.expand_path 'phony/countries/georgia.rb', __dir__
|
|
36
|
+
load File.expand_path 'phony/countries/germany.rb', __dir__
|
|
37
|
+
load File.expand_path 'phony/countries/guinea.rb', __dir__
|
|
38
|
+
load File.expand_path 'phony/countries/india.rb', __dir__
|
|
39
|
+
load File.expand_path 'phony/countries/indonesia.rb', __dir__
|
|
40
|
+
load File.expand_path 'phony/countries/ireland.rb', __dir__
|
|
41
|
+
load File.expand_path 'phony/countries/italy.rb', __dir__
|
|
42
|
+
load File.expand_path 'phony/countries/japan.rb', __dir__
|
|
43
|
+
load File.expand_path 'phony/countries/kyrgyzstan.rb', __dir__
|
|
44
|
+
load File.expand_path 'phony/countries/latvia.rb', __dir__
|
|
45
|
+
load File.expand_path 'phony/countries/libya.rb', __dir__
|
|
46
|
+
load File.expand_path 'phony/countries/malaysia.rb', __dir__
|
|
47
|
+
load File.expand_path 'phony/countries/moldova.rb', __dir__
|
|
48
|
+
load File.expand_path 'phony/countries/montenegro.rb', __dir__
|
|
49
|
+
load File.expand_path 'phony/countries/myanmar.rb', __dir__
|
|
50
|
+
load File.expand_path 'phony/countries/namibia.rb', __dir__
|
|
51
|
+
load File.expand_path 'phony/countries/nepal.rb', __dir__
|
|
52
|
+
load File.expand_path 'phony/countries/netherlands.rb', __dir__
|
|
53
|
+
load File.expand_path 'phony/countries/pakistan.rb', __dir__
|
|
54
|
+
load File.expand_path 'phony/countries/paraguay.rb', __dir__
|
|
55
|
+
load File.expand_path 'phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb', __dir__
|
|
56
|
+
load File.expand_path 'phony/countries/saudi_arabia.rb', __dir__
|
|
57
|
+
load File.expand_path 'phony/countries/serbia.rb', __dir__
|
|
58
|
+
load File.expand_path 'phony/countries/somalia.rb', __dir__
|
|
59
|
+
load File.expand_path 'phony/countries/south_korea.rb', __dir__
|
|
60
|
+
load File.expand_path 'phony/countries/sweden.rb', __dir__
|
|
61
|
+
load File.expand_path 'phony/countries/taiwan.rb', __dir__
|
|
62
|
+
load File.expand_path 'phony/countries/tajikistan.rb', __dir__
|
|
63
|
+
load File.expand_path 'phony/countries/turkmenistan.rb', __dir__
|
|
64
|
+
load File.expand_path 'phony/countries/vietnam.rb', __dir__
|
|
65
|
+
load File.expand_path 'phony/countries/ukraine.rb', __dir__
|
|
66
|
+
load File.expand_path 'phony/countries/united_kingdom.rb', __dir__
|
|
67
|
+
load File.expand_path 'phony/countries/uruguay.rb', __dir__
|
|
68
|
+
load File.expand_path 'phony/countries/zimbabwe.rb', __dir__
|
|
68
69
|
|
|
69
70
|
# All other countries.
|
|
70
71
|
#
|
|
71
|
-
load File.expand_path '
|
|
72
|
+
load File.expand_path 'phony/countries.rb', __dir__
|
|
72
73
|
|
|
73
74
|
# Phony is the main module and is generally used to process
|
|
74
75
|
# E164 phone numbers directly.
|
|
75
76
|
#
|
|
76
77
|
module Phony
|
|
77
|
-
|
|
78
78
|
# Raised in case Phony can't normalize a given number.
|
|
79
79
|
#
|
|
80
80
|
# @example
|
|
@@ -82,21 +82,21 @@ module Phony
|
|
|
82
82
|
#
|
|
83
83
|
class NormalizationError < ArgumentError
|
|
84
84
|
def initialize
|
|
85
|
-
super
|
|
85
|
+
super(%(Phony could not normalize the given number. Is it a phone number?))
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
# Raised in case Phony can't split a given number.
|
|
90
90
|
#
|
|
91
91
|
# @example
|
|
92
92
|
# Phony.split("Fnork!") # Raises a Phony::SplittingError.
|
|
93
93
|
#
|
|
94
94
|
class SplittingError < ArgumentError
|
|
95
|
-
def initialize
|
|
96
|
-
super
|
|
95
|
+
def initialize(number)
|
|
96
|
+
super(%(Phony could not split the given number. Is #{(number.nil? || number == '') ? 'it' : number.inspect} a phone number?))
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
# Raised in case Phony can't format a given number.
|
|
101
101
|
#
|
|
102
102
|
# @example
|
|
@@ -104,7 +104,7 @@ module Phony
|
|
|
104
104
|
#
|
|
105
105
|
class FormattingError < ArgumentError
|
|
106
106
|
def initialize
|
|
107
|
-
super
|
|
107
|
+
super(%(Phony could not format the given number. Is it a phone number?))
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
@@ -113,7 +113,6 @@ module Phony
|
|
|
113
113
|
@codes = CountryCodes.instance
|
|
114
114
|
|
|
115
115
|
class << self
|
|
116
|
-
|
|
117
116
|
# Get the Country for the given CC.
|
|
118
117
|
#
|
|
119
118
|
# @param [String] cc A valid country code.
|
|
@@ -124,7 +123,7 @@ module Phony
|
|
|
124
123
|
# nanp = Phony['1']
|
|
125
124
|
# normalized_number = nanp.normalize number
|
|
126
125
|
#
|
|
127
|
-
def []
|
|
126
|
+
def [](cc)
|
|
128
127
|
@codes[cc]
|
|
129
128
|
end
|
|
130
129
|
|
|
@@ -145,11 +144,12 @@ module Phony
|
|
|
145
144
|
# @example Normalize a phone number assuming it's a NANP number.
|
|
146
145
|
# Phony.normalize("301 555 0100", cc: '1') # => "13015550100"
|
|
147
146
|
#
|
|
148
|
-
def normalize
|
|
149
|
-
raise ArgumentError,
|
|
150
|
-
|
|
147
|
+
def normalize(phone_number, options = {})
|
|
148
|
+
raise ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.normalize(number).' unless phone_number
|
|
149
|
+
|
|
151
150
|
normalize! phone_number.dup, options
|
|
152
151
|
end
|
|
152
|
+
|
|
153
153
|
# A destructive version of {#normalize}.
|
|
154
154
|
#
|
|
155
155
|
# @see #normalize
|
|
@@ -167,7 +167,7 @@ module Phony
|
|
|
167
167
|
# @example Normalize a phone number assuming it's a NANP number.
|
|
168
168
|
# Phony.normalize!("301 555 0100", cc: '1') # => "13015550100"
|
|
169
169
|
#
|
|
170
|
-
def normalize!
|
|
170
|
+
def normalize!(phone_number, options = {})
|
|
171
171
|
@codes.normalize phone_number, options
|
|
172
172
|
rescue
|
|
173
173
|
raise NormalizationError.new
|
|
@@ -187,11 +187,12 @@ module Phony
|
|
|
187
187
|
# @example Split a NANP number.
|
|
188
188
|
# Phony.split("13015550100") # => ["1", "301", "555", "0100"]
|
|
189
189
|
#
|
|
190
|
-
def split
|
|
191
|
-
raise ArgumentError,
|
|
192
|
-
|
|
190
|
+
def split(phone_number)
|
|
191
|
+
raise ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.split(number).' unless phone_number
|
|
192
|
+
|
|
193
193
|
split! phone_number.dup, phone_number
|
|
194
194
|
end
|
|
195
|
+
|
|
195
196
|
# A destructive version of {#split}.
|
|
196
197
|
#
|
|
197
198
|
# @see #split
|
|
@@ -206,7 +207,7 @@ module Phony
|
|
|
206
207
|
# @example Split a NANP number.
|
|
207
208
|
# Phony.split!("13015550100") # => ["1", "301", "555", "0100"]
|
|
208
209
|
#
|
|
209
|
-
def split!
|
|
210
|
+
def split!(phone_number, error_number = nil)
|
|
210
211
|
@codes.split phone_number
|
|
211
212
|
rescue
|
|
212
213
|
# NB The error_number (reference) is used because phone_number is destructively handled.
|
|
@@ -234,10 +235,12 @@ module Phony
|
|
|
234
235
|
# @example Format a NANP number in a specific format.
|
|
235
236
|
# Phony.format("13015550100", :format => '%{cc} (%{trunk}%{ndc}) %{local}') # => "555 0100"
|
|
236
237
|
#
|
|
237
|
-
def format
|
|
238
|
-
raise ArgumentError,
|
|
238
|
+
def format(phone_number, options = {})
|
|
239
|
+
raise ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.format(number).' unless phone_number
|
|
240
|
+
|
|
239
241
|
format! phone_number.dup, options
|
|
240
242
|
end
|
|
243
|
+
|
|
241
244
|
# A destructive version of {#format}.
|
|
242
245
|
#
|
|
243
246
|
# @see #format
|
|
@@ -260,7 +263,7 @@ module Phony
|
|
|
260
263
|
# @example Format a NANP number in local format.
|
|
261
264
|
# Phony.format!("13015550100", :format => :local) # => "555 0100"
|
|
262
265
|
#
|
|
263
|
-
def format!
|
|
266
|
+
def format!(phone_number, options = {})
|
|
264
267
|
@codes.format phone_number, options
|
|
265
268
|
rescue
|
|
266
269
|
raise FormattingError.new
|
|
@@ -274,14 +277,14 @@ module Phony
|
|
|
274
277
|
# If it returns true, it is unclear whether it is plausible,
|
|
275
278
|
# leaning towards being plausible.
|
|
276
279
|
#
|
|
277
|
-
def plausible?
|
|
280
|
+
def plausible?(number, hints = {})
|
|
278
281
|
@codes.plausible? number, hints
|
|
279
282
|
end
|
|
280
283
|
|
|
281
284
|
# Returns true if there is a character in the number
|
|
282
285
|
# after the first four numbers.
|
|
283
286
|
#
|
|
284
|
-
def vanity?
|
|
287
|
+
def vanity?(phone_number)
|
|
285
288
|
@codes.vanity? phone_number.dup
|
|
286
289
|
end
|
|
287
290
|
|
|
@@ -295,10 +298,8 @@ module Phony
|
|
|
295
298
|
# @example De-vanitize a number.
|
|
296
299
|
# Phony.vanity_to_number("1-800-HELLOTHERE") # => "1-800-4355684373"
|
|
297
300
|
#
|
|
298
|
-
def vanity_to_number
|
|
301
|
+
def vanity_to_number(vanity_number)
|
|
299
302
|
@codes.vanity_to_number vanity_number.dup
|
|
300
303
|
end
|
|
301
|
-
|
|
302
304
|
end
|
|
303
|
-
|
|
304
305
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phony
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Hanke
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'Fast international phone number (E164 standard) normalizing, splitting
|
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
|
@@ -17,12 +17,13 @@ email: florian.hanke+phony@gmail.com
|
|
|
17
17
|
executables: []
|
|
18
18
|
extensions: []
|
|
19
19
|
extra_rdoc_files:
|
|
20
|
-
- README.
|
|
20
|
+
- README.md
|
|
21
21
|
files:
|
|
22
|
-
- README.
|
|
22
|
+
- README.md
|
|
23
23
|
- lib/phony.rb
|
|
24
24
|
- lib/phony/config.rb
|
|
25
25
|
- lib/phony/countries.rb
|
|
26
|
+
- lib/phony/countries/argentina.rb
|
|
26
27
|
- lib/phony/countries/austria.rb
|
|
27
28
|
- lib/phony/countries/bangladesh.rb
|
|
28
29
|
- lib/phony/countries/belarus.rb
|
|
@@ -78,27 +79,12 @@ files:
|
|
|
78
79
|
- lib/phony/national_splitters/variable.rb
|
|
79
80
|
- lib/phony/trunk_code.rb
|
|
80
81
|
- lib/phony/vanity.rb
|
|
81
|
-
|
|
82
|
-
- spec/functional/plausibility_spec.rb
|
|
83
|
-
- spec/lib/phony/countries_spec.rb
|
|
84
|
-
- spec/lib/phony/country_codes_spec.rb
|
|
85
|
-
- spec/lib/phony/country_spec.rb
|
|
86
|
-
- spec/lib/phony/dsl_spec.rb
|
|
87
|
-
- spec/lib/phony/local_splitters/fixed_spec.rb
|
|
88
|
-
- spec/lib/phony/local_splitters/regex_spec.rb
|
|
89
|
-
- spec/lib/phony/national_code_spec.rb
|
|
90
|
-
- spec/lib/phony/national_splitters/default_spec.rb
|
|
91
|
-
- spec/lib/phony/national_splitters/fixed_spec.rb
|
|
92
|
-
- spec/lib/phony/national_splitters/none_spec.rb
|
|
93
|
-
- spec/lib/phony/national_splitters/regex_spec.rb
|
|
94
|
-
- spec/lib/phony/national_splitters/variable_spec.rb
|
|
95
|
-
- spec/lib/phony/vanity_spec.rb
|
|
96
|
-
- spec/lib/phony_spec.rb
|
|
97
|
-
homepage: http://github.com/floere/phony
|
|
82
|
+
homepage: https://github.com/floere/phony
|
|
98
83
|
licenses:
|
|
99
84
|
- MIT
|
|
100
|
-
metadata:
|
|
101
|
-
|
|
85
|
+
metadata:
|
|
86
|
+
rubygems_mfa_required: 'true'
|
|
87
|
+
post_install_message:
|
|
102
88
|
rdoc_options: []
|
|
103
89
|
require_paths:
|
|
104
90
|
- lib
|
|
@@ -106,33 +92,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
106
92
|
requirements:
|
|
107
93
|
- - ">="
|
|
108
94
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: '
|
|
95
|
+
version: '3.2'
|
|
110
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
97
|
requirements:
|
|
112
98
|
- - ">="
|
|
113
99
|
- !ruby/object:Gem::Version
|
|
114
100
|
version: '0'
|
|
115
101
|
requirements: []
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
signing_key:
|
|
102
|
+
rubygems_version: 3.5.21
|
|
103
|
+
signing_key:
|
|
119
104
|
specification_version: 4
|
|
120
105
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|
|
121
106
|
formatting.
|
|
122
|
-
test_files:
|
|
123
|
-
- spec/lib/phony_spec.rb
|
|
124
|
-
- spec/lib/phony/country_spec.rb
|
|
125
|
-
- spec/lib/phony/national_code_spec.rb
|
|
126
|
-
- spec/lib/phony/countries_spec.rb
|
|
127
|
-
- spec/lib/phony/dsl_spec.rb
|
|
128
|
-
- spec/lib/phony/national_splitters/variable_spec.rb
|
|
129
|
-
- spec/lib/phony/national_splitters/none_spec.rb
|
|
130
|
-
- spec/lib/phony/national_splitters/regex_spec.rb
|
|
131
|
-
- spec/lib/phony/national_splitters/fixed_spec.rb
|
|
132
|
-
- spec/lib/phony/national_splitters/default_spec.rb
|
|
133
|
-
- spec/lib/phony/country_codes_spec.rb
|
|
134
|
-
- spec/lib/phony/local_splitters/regex_spec.rb
|
|
135
|
-
- spec/lib/phony/local_splitters/fixed_spec.rb
|
|
136
|
-
- spec/lib/phony/vanity_spec.rb
|
|
137
|
-
- spec/functional/config_spec.rb
|
|
138
|
-
- spec/functional/plausibility_spec.rb
|
|
107
|
+
test_files: []
|
data/README.textile
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"!{float:right}https://secure.travis-ci.org/floere/phony.png!":http://travis-ci.org/floere/phony
|
|
2
|
-
!https://coveralls.io/repos/floere/phony/badge.svg?branch=master(Coverage Status)!:https://coveralls.io/r/floere/phony?branch=master
|
|
3
|
-
"!https://codeclimate.com/github/floere/phony.png!":https://codeclimate.com/github/floere/phony
|
|
4
|
-
!http://inch-ci.org/github/floere/phony.png!:http://inch-ci.org/github/floere/phony
|
|
5
|
-
|
|
6
|
-
h1. Phony
|
|
7
|
-
|
|
8
|
-
Disclaimer: Phony works with international numbers only, such as @61 412 345 678@!
|
|
9
|
-
|
|
10
|
-
The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.
|
|
11
|
-
|
|
12
|
-
Used in: "airbnb.com":http://airbnb.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
|
|
13
|
-
|
|
14
|
-
h2(#memory). Runtime Memory Usage
|
|
15
|
-
|
|
16
|
-
According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 1MB of memory per Ruby process.
|
|
17
|
-
Usage was generated using (look for @Total retained@): @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@
|
|
18
|
-
|
|
19
|
-
h2. Description
|
|
20
|
-
|
|
21
|
-
This gem normalizes, formats and splits "*E164 phone numbers*":http://en.wikipedia.org/wiki/E.164. A valid E164 phone number *must* include a country code.
|
|
22
|
-
|
|
23
|
-
E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. For example, the Australian number @+61 412 345 678@ can be broken down into the following components:
|
|
24
|
-
* Country Code (CC): a country code of @61@
|
|
25
|
-
* National Destination Code (NDC): a mobile number denoted by the @4@ (specific to Australia)
|
|
26
|
-
* Local Number Part: a subscriber number of @12 345 678@
|
|
27
|
-
|
|
28
|
-
It currently handles the countries listed at the end of this README.
|
|
29
|
-
|
|
30
|
-
It is covered by roughly 2,250 tests that run in 2 seconds (April 2019).
|
|
31
|
-
If it doesn't work, please "enter an issue":http://github.com/floere/phony/issues or better, fork and "send a pull request":http://github.com/floere/phony/pulls.
|
|
32
|
-
|
|
33
|
-
h2. Installation
|
|
34
|
-
|
|
35
|
-
With Rails? Check out: https://github.com/joost/phony_rails.
|
|
36
|
-
|
|
37
|
-
With Bundler: Append @gem 'phony'@ to your @Gemfile@ and @bundle install@ it.
|
|
38
|
-
|
|
39
|
-
Without Bundler: Run @gem install phony@ from your command line.
|
|
40
|
-
|
|
41
|
-
h2(#usage). Usage docs
|
|
42
|
-
|
|
43
|
-
Phony uses "qed":https://github.com/rubyworks/qed as docs and to run its functional tests. Start here for usage docs: "Usage index":./qed/index.md.
|
|
44
|
-
|
|
45
|
-
h3(#normalizing). Phony.normalize(number)
|
|
46
|
-
|
|
47
|
-
Normalize intelligently removes all non-numeric characters of a number. Do it before storing a number in a DB.
|
|
48
|
-
|
|
49
|
-
"Phony.normalize docs":./qed/normalize.md
|
|
50
|
-
|
|
51
|
-
@Phony.normalize('1-888-407-4747').assert == '18884074747'@
|
|
52
|
-
|
|
53
|
-
h3(#formatting). Phony.format(number, options = {})
|
|
54
|
-
|
|
55
|
-
Format formats a normalized number according to a country's predominant formatting. Lots of options for int'l, national, local formatting.
|
|
56
|
-
|
|
57
|
-
"Phony.format docs":./qed/format.md
|
|
58
|
-
|
|
59
|
-
@Phony.format('41443643532').assert == '+41 44 364 35 32'@
|
|
60
|
-
|
|
61
|
-
h3(#plausibility). Phony.plausible?(number, options = {})
|
|
62
|
-
|
|
63
|
-
Is a number plausible?
|
|
64
|
-
|
|
65
|
-
"Phony.plausible? docs":./qed/plausibility.md
|
|
66
|
-
|
|
67
|
-
@Phony.assert.plausible?('+41 44 111 22 33')@
|
|
68
|
-
|
|
69
|
-
h3(#splitting). Phony.split(number)
|
|
70
|
-
|
|
71
|
-
Split a number into its parts: CC, NDC, local.
|
|
72
|
-
|
|
73
|
-
"Phony.split docs":./qed/split.md
|
|
74
|
-
|
|
75
|
-
@Phony.split('3928061371').assert == ['39', '2', '806', '1371']@
|
|
76
|
-
|
|
77
|
-
NB If a country does not have an NDC, @#split@ will return @false@ in the NDC position, for example for Denmark:
|
|
78
|
-
|
|
79
|
-
@Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']@
|
|
80
|
-
|
|
81
|
-
h3(#loading). Loading only a country subset (Phony 2.18.0+).
|
|
82
|
-
|
|
83
|
-
Use this in case you'd like to save "memory":#memory that is used by Phony's CC rules.
|
|
84
|
-
|
|
85
|
-
"Phony::Config.load docs":./qed/config.md
|
|
86
|
-
|
|
87
|
-
First, @require 'phony/config'@.
|
|
88
|
-
Then, one of the following, which will load the rest of Phony.
|
|
89
|
-
|
|
90
|
-
Load only these CCs:
|
|
91
|
-
@Phony::Config.load(only: ['41', '44'])@
|
|
92
|
-
|
|
93
|
-
Loads everything except these CCs:
|
|
94
|
-
@Phony::Config.load(except: ['41', '44'])@
|
|
95
|
-
|
|
96
|
-
Convenience form of @only@:
|
|
97
|
-
@Phony::Config.load('41', '44')@
|
|
98
|
-
|
|
99
|
-
Each of these loads the rest of Phony.
|
|
100
|
-
|
|
101
|
-
Memory usage can be checked using (look for @Total retained@):
|
|
102
|
-
@ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony/config"; Phony::Config.load("1") }.pretty_print'@
|
|
103
|
-
For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
|
-
|
|
105
|
-
h2. List of Handled Countries
|
|
106
|
-
|
|
107
|
-
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
|
108
|
-
|
|
109
|
-
h2. License
|
|
110
|
-
|
|
111
|
-
MIT.
|
|
112
|
-
See "LICENSE":./LICENSE file.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
#
|
|
3
|
-
describe 'Phony::Config' do
|
|
4
|
-
describe 'load' do
|
|
5
|
-
before do
|
|
6
|
-
# NOTE We redefine Phony as if it was not loaded for this set of tests.
|
|
7
|
-
Object.__send__(:remove_const, :Phony) if Object.constants.include?(:Phony)
|
|
8
|
-
|
|
9
|
-
load 'phony/config.rb'
|
|
10
|
-
end
|
|
11
|
-
after(:all) do
|
|
12
|
-
# After running this suite, we load all of Phony for the following tests.
|
|
13
|
-
load 'phony/config.rb'
|
|
14
|
-
|
|
15
|
-
Phony::Config.load
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'does not fail when loading all' do
|
|
19
|
-
Phony::Config.load
|
|
20
|
-
|
|
21
|
-
Phony.split('15551115511').should == ['1', '555', '111', '5511']
|
|
22
|
-
end
|
|
23
|
-
it 'raises when a CC is used that has not been loaded.' do
|
|
24
|
-
Phony::Config.load('41')
|
|
25
|
-
|
|
26
|
-
expect { Phony.split('15551115511') }.to raise_error
|
|
27
|
-
end
|
|
28
|
-
it 'raises when a CC is used that has not been loaded.' do
|
|
29
|
-
Phony::Config.load(only: ['41'])
|
|
30
|
-
|
|
31
|
-
expect { Phony.split('15551115511') }.to raise_error
|
|
32
|
-
end
|
|
33
|
-
it 'raises when a CC is used that has not been loaded.' do
|
|
34
|
-
Phony::Config.load(except: ['1'])
|
|
35
|
-
|
|
36
|
-
expect { Phony.split('15551115511') }.to raise_error
|
|
37
|
-
end
|
|
38
|
-
it 'does not raise when a CC is used that has been loaded.' do
|
|
39
|
-
Phony::Config.load(except: ['41'])
|
|
40
|
-
|
|
41
|
-
Phony.split('15551115511').should == ['1', '555', '111', '5511']
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|