phony 2.20.5 → 3.0.2

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -0
  3. data/lib/phony/config.rb +25 -26
  4. data/lib/phony/countries/argentina.rb +311 -314
  5. data/lib/phony/countries/austria.rb +71 -72
  6. data/lib/phony/countries/bangladesh.rb +27 -28
  7. data/lib/phony/countries/belarus.rb +110 -111
  8. data/lib/phony/countries/brazil.rb +93 -93
  9. data/lib/phony/countries/cambodia.rb +9 -9
  10. data/lib/phony/countries/china.rb +22 -21
  11. data/lib/phony/countries/croatia.rb +6 -5
  12. data/lib/phony/countries/georgia.rb +84 -84
  13. data/lib/phony/countries/germany.rb +4067 -4068
  14. data/lib/phony/countries/guinea.rb +8 -8
  15. data/lib/phony/countries/india.rb +31 -34
  16. data/lib/phony/countries/indonesia.rb +57 -46
  17. data/lib/phony/countries/ireland.rb +4 -5
  18. data/lib/phony/countries/italy.rb +54 -52
  19. data/lib/phony/countries/japan.rb +456 -456
  20. data/lib/phony/countries/kyrgyzstan.rb +109 -109
  21. data/lib/phony/countries/latvia.rb +34 -34
  22. data/lib/phony/countries/libya.rb +109 -107
  23. data/lib/phony/countries/malaysia.rb +12 -12
  24. data/lib/phony/countries/moldova.rb +42 -42
  25. data/lib/phony/countries/montenegro.rb +24 -20
  26. data/lib/phony/countries/myanmar.rb +39 -39
  27. data/lib/phony/countries/namibia.rb +35 -29
  28. data/lib/phony/countries/nepal.rb +60 -62
  29. data/lib/phony/countries/netherlands.rb +13 -13
  30. data/lib/phony/countries/pakistan.rb +135 -111
  31. data/lib/phony/countries/paraguay.rb +135 -135
  32. data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +125 -128
  33. data/lib/phony/countries/saudi_arabia.rb +5 -5
  34. data/lib/phony/countries/serbia.rb +47 -39
  35. data/lib/phony/countries/somalia.rb +18 -18
  36. data/lib/phony/countries/south_korea.rb +16 -13
  37. data/lib/phony/countries/sweden.rb +356 -48
  38. data/lib/phony/countries/taiwan.rb +20 -19
  39. data/lib/phony/countries/tajikistan.rb +70 -70
  40. data/lib/phony/countries/turkmenistan.rb +65 -65
  41. data/lib/phony/countries/ukraine.rb +607 -607
  42. data/lib/phony/countries/united_kingdom.rb +66 -66
  43. data/lib/phony/countries/uruguay.rb +40 -41
  44. data/lib/phony/countries/vietnam.rb +19 -14
  45. data/lib/phony/countries/zimbabwe.rb +31 -31
  46. data/lib/phony/countries.rb +469 -447
  47. data/lib/phony/country.rb +44 -44
  48. data/lib/phony/country_codes.rb +67 -60
  49. data/lib/phony/dsl.rb +23 -26
  50. data/lib/phony/local_splitters/fixed.rb +23 -30
  51. data/lib/phony/local_splitters/regex.rb +30 -31
  52. data/lib/phony/national_code.rb +7 -10
  53. data/lib/phony/national_splitters/default.rb +9 -11
  54. data/lib/phony/national_splitters/dsl.rb +8 -18
  55. data/lib/phony/national_splitters/fixed.rb +12 -15
  56. data/lib/phony/national_splitters/none.rb +7 -11
  57. data/lib/phony/national_splitters/regex.rb +13 -17
  58. data/lib/phony/national_splitters/variable.rb +37 -38
  59. data/lib/phony/trunk_code.rb +20 -20
  60. data/lib/phony/vanity.rb +12 -13
  61. data/lib/phony.rb +84 -84
  62. metadata +9 -42
  63. data/README.textile +0 -116
  64. data/spec/functional/config_spec.rb +0 -44
  65. data/spec/functional/plausibility_spec.rb +0 -674
  66. data/spec/lib/phony/countries_spec.rb +0 -1454
  67. data/spec/lib/phony/country_codes_spec.rb +0 -227
  68. data/spec/lib/phony/country_spec.rb +0 -104
  69. data/spec/lib/phony/dsl_spec.rb +0 -28
  70. data/spec/lib/phony/local_splitters/fixed_spec.rb +0 -56
  71. data/spec/lib/phony/local_splitters/regex_spec.rb +0 -94
  72. data/spec/lib/phony/national_code_spec.rb +0 -61
  73. data/spec/lib/phony/national_splitters/default_spec.rb +0 -34
  74. data/spec/lib/phony/national_splitters/fixed_spec.rb +0 -45
  75. data/spec/lib/phony/national_splitters/none_spec.rb +0 -28
  76. data/spec/lib/phony/national_splitters/regex_spec.rb +0 -23
  77. data/spec/lib/phony/national_splitters/variable_spec.rb +0 -35
  78. data/spec/lib/phony/trunk_code_spec.rb +0 -85
  79. data/spec/lib/phony/vanity_spec.rb +0 -30
  80. 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
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.freeze,
12
- '2223334445556667777888999922233344455566677778889999'.freeze
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 number
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? number
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 number
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,81 +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 '../phony/config.rb', __FILE__
8
- load File.expand_path '../phony/vanity.rb', __FILE__
9
- load File.expand_path '../phony/local_splitters/fixed.rb', __FILE__
10
- load File.expand_path '../phony/local_splitters/regex.rb', __FILE__
11
- load File.expand_path '../phony/national_splitters/dsl.rb', __FILE__
12
- load File.expand_path '../phony/national_splitters/fixed.rb', __FILE__
13
- load File.expand_path '../phony/national_splitters/variable.rb', __FILE__
14
- load File.expand_path '../phony/national_splitters/regex.rb', __FILE__
15
- load File.expand_path '../phony/national_splitters/default.rb', __FILE__
16
- load File.expand_path '../phony/national_splitters/none.rb', __FILE__
17
- load File.expand_path '../phony/national_code.rb', __FILE__
18
- load File.expand_path '../phony/country.rb', __FILE__
19
- load File.expand_path '../phony/trunk_code.rb', __FILE__
20
- load File.expand_path '../phony/country_codes.rb', __FILE__
21
- load File.expand_path '../phony/dsl.rb', __FILE__
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 '../phony/countries/argentina.rb', __FILE__
28
- load File.expand_path '../phony/countries/austria.rb', __FILE__
29
- load File.expand_path '../phony/countries/bangladesh.rb', __FILE__
30
- load File.expand_path '../phony/countries/belarus.rb', __FILE__
31
- load File.expand_path '../phony/countries/brazil.rb', __FILE__
32
- load File.expand_path '../phony/countries/cambodia.rb', __FILE__
33
- load File.expand_path '../phony/countries/croatia.rb', __FILE__
34
- load File.expand_path '../phony/countries/china.rb', __FILE__
35
- load File.expand_path '../phony/countries/georgia.rb', __FILE__
36
- load File.expand_path '../phony/countries/germany.rb', __FILE__
37
- load File.expand_path '../phony/countries/guinea.rb', __FILE__
38
- load File.expand_path '../phony/countries/india.rb', __FILE__
39
- load File.expand_path '../phony/countries/indonesia.rb', __FILE__
40
- load File.expand_path '../phony/countries/ireland.rb', __FILE__
41
- load File.expand_path '../phony/countries/italy.rb', __FILE__
42
- load File.expand_path '../phony/countries/japan.rb', __FILE__
43
- load File.expand_path '../phony/countries/kyrgyzstan.rb', __FILE__
44
- load File.expand_path '../phony/countries/latvia.rb', __FILE__
45
- load File.expand_path '../phony/countries/libya.rb', __FILE__
46
- load File.expand_path '../phony/countries/malaysia.rb', __FILE__
47
- load File.expand_path '../phony/countries/moldova.rb', __FILE__
48
- load File.expand_path '../phony/countries/montenegro.rb', __FILE__
49
- load File.expand_path '../phony/countries/myanmar.rb', __FILE__
50
- load File.expand_path '../phony/countries/namibia.rb', __FILE__
51
- load File.expand_path '../phony/countries/nepal.rb', __FILE__
52
- load File.expand_path '../phony/countries/netherlands.rb', __FILE__
53
- load File.expand_path '../phony/countries/pakistan.rb', __FILE__
54
- load File.expand_path '../phony/countries/paraguay.rb', __FILE__
55
- load File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb', __FILE__
56
- load File.expand_path '../phony/countries/saudi_arabia.rb', __FILE__
57
- load File.expand_path '../phony/countries/serbia.rb', __FILE__
58
- load File.expand_path '../phony/countries/somalia.rb', __FILE__
59
- load File.expand_path '../phony/countries/south_korea.rb', __FILE__
60
- load File.expand_path '../phony/countries/sweden.rb', __FILE__
61
- load File.expand_path '../phony/countries/taiwan.rb', __FILE__
62
- load File.expand_path '../phony/countries/tajikistan.rb', __FILE__
63
- load File.expand_path '../phony/countries/turkmenistan.rb', __FILE__
64
- load File.expand_path '../phony/countries/vietnam.rb', __FILE__
65
- load File.expand_path '../phony/countries/ukraine.rb', __FILE__
66
- load File.expand_path '../phony/countries/united_kingdom.rb', __FILE__
67
- load File.expand_path '../phony/countries/uruguay.rb', __FILE__
68
- load File.expand_path '../phony/countries/zimbabwe.rb', __FILE__
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__
69
69
 
70
70
  # All other countries.
71
71
  #
72
- load File.expand_path '../phony/countries.rb', __FILE__
72
+ load File.expand_path 'phony/countries.rb', __dir__
73
73
 
74
74
  # Phony is the main module and is generally used to process
75
75
  # E164 phone numbers directly.
76
76
  #
77
77
  module Phony
78
-
79
78
  # Raised in case Phony can't normalize a given number.
80
79
  #
81
80
  # @example
@@ -83,21 +82,21 @@ module Phony
83
82
  #
84
83
  class NormalizationError < ArgumentError
85
84
  def initialize
86
- super %Q{Phony could not normalize the given number. Is it a phone number?}
85
+ super(%(Phony could not normalize the given number. Is it a phone number?))
87
86
  end
88
87
  end
89
-
88
+
90
89
  # Raised in case Phony can't split a given number.
91
90
  #
92
91
  # @example
93
92
  # Phony.split("Fnork!") # Raises a Phony::SplittingError.
94
93
  #
95
94
  class SplittingError < ArgumentError
96
- def initialize number
97
- super %Q{Phony could not split the given number. Is #{(number.nil? || number == '') ? 'it' : number.inspect} a phone number?}
95
+ def initialize(number)
96
+ super(%(Phony could not split the given number. Is #{(number.nil? || number == '') ? 'it' : number.inspect} a phone number?))
98
97
  end
99
98
  end
100
-
99
+
101
100
  # Raised in case Phony can't format a given number.
102
101
  #
103
102
  # @example
@@ -105,7 +104,7 @@ module Phony
105
104
  #
106
105
  class FormattingError < ArgumentError
107
106
  def initialize
108
- super %Q{Phony could not format the given number. Is it a phone number?}
107
+ super(%(Phony could not format the given number. Is it a phone number?))
109
108
  end
110
109
  end
111
110
 
@@ -114,7 +113,6 @@ module Phony
114
113
  @codes = CountryCodes.instance
115
114
 
116
115
  class << self
117
-
118
116
  # Get the Country for the given CC.
119
117
  #
120
118
  # @param [String] cc A valid country code.
@@ -125,7 +123,7 @@ module Phony
125
123
  # nanp = Phony['1']
126
124
  # normalized_number = nanp.normalize number
127
125
  #
128
- def [] cc
126
+ def [](cc)
129
127
  @codes[cc]
130
128
  end
131
129
 
@@ -146,11 +144,12 @@ module Phony
146
144
  # @example Normalize a phone number assuming it's a NANP number.
147
145
  # Phony.normalize("301 555 0100", cc: '1') # => "13015550100"
148
146
  #
149
- def normalize phone_number, options = {}
150
- raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number)." unless phone_number
151
-
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
+
152
150
  normalize! phone_number.dup, options
153
151
  end
152
+
154
153
  # A destructive version of {#normalize}.
155
154
  #
156
155
  # @see #normalize
@@ -168,7 +167,7 @@ module Phony
168
167
  # @example Normalize a phone number assuming it's a NANP number.
169
168
  # Phony.normalize!("301 555 0100", cc: '1') # => "13015550100"
170
169
  #
171
- def normalize! phone_number, options = {}
170
+ def normalize!(phone_number, options = {})
172
171
  @codes.normalize phone_number, options
173
172
  rescue
174
173
  raise NormalizationError.new
@@ -188,11 +187,12 @@ module Phony
188
187
  # @example Split a NANP number.
189
188
  # Phony.split("13015550100") # => ["1", "301", "555", "0100"]
190
189
  #
191
- def split phone_number
192
- raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number)." unless phone_number
193
-
190
+ def split(phone_number)
191
+ raise ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.split(number).' unless phone_number
192
+
194
193
  split! phone_number.dup, phone_number
195
194
  end
195
+
196
196
  # A destructive version of {#split}.
197
197
  #
198
198
  # @see #split
@@ -207,7 +207,7 @@ module Phony
207
207
  # @example Split a NANP number.
208
208
  # Phony.split!("13015550100") # => ["1", "301", "555", "0100"]
209
209
  #
210
- def split! phone_number, error_number = nil
210
+ def split!(phone_number, error_number = nil)
211
211
  @codes.split phone_number
212
212
  rescue
213
213
  # NB The error_number (reference) is used because phone_number is destructively handled.
@@ -235,10 +235,12 @@ module Phony
235
235
  # @example Format a NANP number in a specific format.
236
236
  # Phony.format("13015550100", :format => '%{cc} (%{trunk}%{ndc}) %{local}') # => "555 0100"
237
237
  #
238
- def format phone_number, options = {}
239
- raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
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
+
240
241
  format! phone_number.dup, options
241
242
  end
243
+
242
244
  # A destructive version of {#format}.
243
245
  #
244
246
  # @see #format
@@ -261,7 +263,7 @@ module Phony
261
263
  # @example Format a NANP number in local format.
262
264
  # Phony.format!("13015550100", :format => :local) # => "555 0100"
263
265
  #
264
- def format! phone_number, options = {}
266
+ def format!(phone_number, options = {})
265
267
  @codes.format phone_number, options
266
268
  rescue
267
269
  raise FormattingError.new
@@ -275,14 +277,14 @@ module Phony
275
277
  # If it returns true, it is unclear whether it is plausible,
276
278
  # leaning towards being plausible.
277
279
  #
278
- def plausible? number, hints = {}
280
+ def plausible?(number, hints = {})
279
281
  @codes.plausible? number, hints
280
282
  end
281
283
 
282
284
  # Returns true if there is a character in the number
283
285
  # after the first four numbers.
284
286
  #
285
- def vanity? phone_number
287
+ def vanity?(phone_number)
286
288
  @codes.vanity? phone_number.dup
287
289
  end
288
290
 
@@ -296,10 +298,8 @@ module Phony
296
298
  # @example De-vanitize a number.
297
299
  # Phony.vanity_to_number("1-800-HELLOTHERE") # => "1-800-4355684373"
298
300
  #
299
- def vanity_to_number vanity_number
301
+ def vanity_to_number(vanity_number)
300
302
  @codes.vanity_to_number vanity_number.dup
301
303
  end
302
-
303
304
  end
304
-
305
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: 2.20.5
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2025-12-13 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,9 +17,9 @@ email: florian.hanke+phony@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files:
20
- - README.textile
20
+ - README.md
21
21
  files:
22
- - README.textile
22
+ - README.md
23
23
  - lib/phony.rb
24
24
  - lib/phony/config.rb
25
25
  - lib/phony/countries.rb
@@ -79,27 +79,11 @@ files:
79
79
  - lib/phony/national_splitters/variable.rb
80
80
  - lib/phony/trunk_code.rb
81
81
  - lib/phony/vanity.rb
82
- - spec/functional/config_spec.rb
83
- - spec/functional/plausibility_spec.rb
84
- - spec/lib/phony/countries_spec.rb
85
- - spec/lib/phony/country_codes_spec.rb
86
- - spec/lib/phony/country_spec.rb
87
- - spec/lib/phony/dsl_spec.rb
88
- - spec/lib/phony/local_splitters/fixed_spec.rb
89
- - spec/lib/phony/local_splitters/regex_spec.rb
90
- - spec/lib/phony/national_code_spec.rb
91
- - spec/lib/phony/national_splitters/default_spec.rb
92
- - spec/lib/phony/national_splitters/fixed_spec.rb
93
- - spec/lib/phony/national_splitters/none_spec.rb
94
- - spec/lib/phony/national_splitters/regex_spec.rb
95
- - spec/lib/phony/national_splitters/variable_spec.rb
96
- - spec/lib/phony/trunk_code_spec.rb
97
- - spec/lib/phony/vanity_spec.rb
98
- - spec/lib/phony_spec.rb
99
82
  homepage: https://github.com/floere/phony
100
83
  licenses:
101
84
  - MIT
102
- metadata: {}
85
+ metadata:
86
+ rubygems_mfa_required: 'true'
103
87
  post_install_message:
104
88
  rdoc_options: []
105
89
  require_paths:
@@ -108,33 +92,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
92
  requirements:
109
93
  - - ">="
110
94
  - !ruby/object:Gem::Version
111
- version: '0'
95
+ version: '3.2'
112
96
  required_rubygems_version: !ruby/object:Gem::Requirement
113
97
  requirements:
114
98
  - - ">="
115
99
  - !ruby/object:Gem::Version
116
100
  version: '0'
117
101
  requirements: []
118
- rubygems_version: 3.3.26
102
+ rubygems_version: 3.5.21
119
103
  signing_key:
120
104
  specification_version: 4
121
105
  summary: Fast international phone number (E164 standard) normalizing, splitting and
122
106
  formatting.
123
- test_files:
124
- - spec/functional/config_spec.rb
125
- - spec/functional/plausibility_spec.rb
126
- - spec/lib/phony/countries_spec.rb
127
- - spec/lib/phony/country_codes_spec.rb
128
- - spec/lib/phony/country_spec.rb
129
- - spec/lib/phony/dsl_spec.rb
130
- - spec/lib/phony/local_splitters/fixed_spec.rb
131
- - spec/lib/phony/local_splitters/regex_spec.rb
132
- - spec/lib/phony/national_code_spec.rb
133
- - spec/lib/phony/national_splitters/default_spec.rb
134
- - spec/lib/phony/national_splitters/fixed_spec.rb
135
- - spec/lib/phony/national_splitters/none_spec.rb
136
- - spec/lib/phony/national_splitters/regex_spec.rb
137
- - spec/lib/phony/national_splitters/variable_spec.rb
138
- - spec/lib/phony/trunk_code_spec.rb
139
- - spec/lib/phony/vanity_spec.rb
140
- - spec/lib/phony_spec.rb
107
+ test_files: []
data/README.textile DELETED
@@ -1,116 +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, Japanese, 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. Proud Sponsors
110
-
111
- * Renuo AG (July 22 –): "Github":https://github.com/renuo, "Homepage":https://www.renuo.ch
112
-
113
- h2. License
114
-
115
- MIT.
116
- 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
- expect(Phony.split('15551115511')).to eq ['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(Phony::SplittingError)
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(Phony::SplittingError)
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(Phony::SplittingError)
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
- expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
42
- end
43
- end
44
- end