telephone_number 1.4.6 → 1.4.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +11 -5
  5. data/data/geocoding/de/352.dat +0 -0
  6. data/data/geocoding/de/352.txt +0 -1
  7. data/data/geocoding/de/43.dat +0 -0
  8. data/data/geocoding/de/43.txt +2 -0
  9. data/data/geocoding/de/49.dat +0 -0
  10. data/data/geocoding/de/49.txt +3 -3
  11. data/data/geocoding/en/1.dat +0 -0
  12. data/data/geocoding/en/1.txt +441 -12
  13. data/data/geocoding/en/212.dat +0 -0
  14. data/data/geocoding/en/212.txt +12 -4
  15. data/data/geocoding/en/213.dat +0 -0
  16. data/data/geocoding/en/213.txt +1 -0
  17. data/data/geocoding/en/221.dat +0 -0
  18. data/data/geocoding/en/221.txt +7 -1
  19. data/data/geocoding/en/224.dat +0 -0
  20. data/data/geocoding/en/224.txt +1 -1
  21. data/data/geocoding/en/225.dat +0 -0
  22. data/data/geocoding/en/225.txt +36 -12
  23. data/data/geocoding/en/233.dat +0 -0
  24. data/data/geocoding/en/233.txt +1 -0
  25. data/data/geocoding/en/234.dat +0 -0
  26. data/data/geocoding/en/234.txt +16 -1
  27. data/data/geocoding/en/236.dat +0 -0
  28. data/data/geocoding/en/236.txt +15 -0
  29. data/data/geocoding/en/238.dat +0 -0
  30. data/data/geocoding/en/238.txt +3 -3
  31. data/data/geocoding/en/252.dat +0 -0
  32. data/data/geocoding/en/252.txt +0 -1
  33. data/data/geocoding/en/264.dat +0 -0
  34. data/data/geocoding/en/264.txt +2 -0
  35. data/data/geocoding/en/267.dat +0 -0
  36. data/data/geocoding/en/267.txt +1 -0
  37. data/data/geocoding/en/290.dat +0 -0
  38. data/data/geocoding/en/290.txt +6 -1
  39. data/data/geocoding/en/33.txt +115 -1
  40. data/data/geocoding/en/352.dat +0 -0
  41. data/data/geocoding/en/352.txt +0 -1
  42. data/data/geocoding/en/370.dat +0 -0
  43. data/data/geocoding/en/370.txt +9 -2
  44. data/data/geocoding/en/374.dat +0 -0
  45. data/data/geocoding/en/374.txt +0 -5
  46. data/data/geocoding/en/380.dat +0 -0
  47. data/data/geocoding/en/380.txt +1 -1
  48. data/data/geocoding/en/389.dat +0 -0
  49. data/data/geocoding/en/389.txt +29 -2
  50. data/data/geocoding/en/421.dat +0 -0
  51. data/data/geocoding/en/421.txt +15 -14
  52. data/data/geocoding/en/43.dat +0 -0
  53. data/data/geocoding/en/43.txt +2 -0
  54. data/data/geocoding/en/44.dat +0 -0
  55. data/data/geocoding/en/44.txt +17 -6
  56. data/data/geocoding/en/49.dat +0 -0
  57. data/data/geocoding/en/49.txt +3 -3
  58. data/data/geocoding/en/504.dat +0 -0
  59. data/data/geocoding/en/504.txt +77 -2
  60. data/data/geocoding/en/52.dat +0 -0
  61. data/data/geocoding/en/52.txt +2 -0
  62. data/data/geocoding/en/54.dat +0 -0
  63. data/data/geocoding/en/54.txt +18 -3
  64. data/data/geocoding/en/55.dat +0 -0
  65. data/data/geocoding/en/55.txt +1 -1
  66. data/data/geocoding/en/56.dat +0 -0
  67. data/data/geocoding/en/56.txt +38 -1
  68. data/data/geocoding/en/57.dat +0 -0
  69. data/data/geocoding/en/57.txt +149 -0
  70. data/data/geocoding/en/58.dat +0 -0
  71. data/data/geocoding/en/58.txt +21 -12
  72. data/data/geocoding/en/593.dat +0 -0
  73. data/data/geocoding/en/593.txt +21 -0
  74. data/data/geocoding/en/595.dat +0 -0
  75. data/data/geocoding/en/595.txt +73 -0
  76. data/data/geocoding/en/598.dat +0 -0
  77. data/data/geocoding/en/598.txt +41 -0
  78. data/data/geocoding/en/599.dat +0 -0
  79. data/data/geocoding/en/599.txt +8 -2
  80. data/data/geocoding/en/60.dat +0 -0
  81. data/data/geocoding/en/60.txt +9 -8
  82. data/data/geocoding/en/61.dat +0 -0
  83. data/data/geocoding/en/61.txt +20670 -2002
  84. data/data/geocoding/en/63.dat +0 -0
  85. data/data/geocoding/en/63.txt +61 -0
  86. data/data/geocoding/en/64.dat +0 -0
  87. data/data/geocoding/en/64.txt +2862 -108
  88. data/data/geocoding/en/66.dat +0 -0
  89. data/data/geocoding/en/66.txt +4 -0
  90. data/data/geocoding/en/670.dat +0 -0
  91. data/data/geocoding/en/670.txt +31 -0
  92. data/data/geocoding/en/672.dat +0 -0
  93. data/data/geocoding/en/672.txt +18 -0
  94. data/data/geocoding/en/678.dat +0 -0
  95. data/data/geocoding/en/678.txt +27 -0
  96. data/data/geocoding/en/680.dat +0 -0
  97. data/data/geocoding/en/680.txt +1 -1
  98. data/data/geocoding/en/685.dat +0 -0
  99. data/data/geocoding/en/685.txt +27 -0
  100. data/data/geocoding/en/686.dat +0 -0
  101. data/data/geocoding/en/686.txt +0 -1
  102. data/data/geocoding/en/689.dat +0 -0
  103. data/data/geocoding/en/689.txt +24 -0
  104. data/data/geocoding/en/690.dat +0 -0
  105. data/data/geocoding/en/690.txt +17 -0
  106. data/data/geocoding/en/7.dat +0 -0
  107. data/data/geocoding/en/7.txt +3 -0
  108. data/data/geocoding/en/81.dat +0 -0
  109. data/data/geocoding/en/81.txt +10 -2
  110. data/data/geocoding/en/850.dat +0 -0
  111. data/data/geocoding/en/850.txt +31 -0
  112. data/data/geocoding/en/880.dat +0 -0
  113. data/data/geocoding/en/880.txt +252 -614
  114. data/data/geocoding/en/92.dat +0 -0
  115. data/data/geocoding/en/92.txt +760 -0
  116. data/data/geocoding/en/94.dat +0 -0
  117. data/data/geocoding/en/94.txt +2 -2
  118. data/data/geocoding/en/961.dat +0 -0
  119. data/data/geocoding/en/961.txt +23 -0
  120. data/data/geocoding/en/962.dat +0 -0
  121. data/data/geocoding/en/962.txt +24 -2
  122. data/data/geocoding/en/963.dat +0 -0
  123. data/data/geocoding/en/963.txt +35 -0
  124. data/data/geocoding/en/967.dat +0 -0
  125. data/data/geocoding/en/967.txt +98 -0
  126. data/data/geocoding/en/970.dat +0 -0
  127. data/data/geocoding/en/970.txt +29 -0
  128. data/data/geocoding/en/993.dat +0 -0
  129. data/data/geocoding/en/993.txt +5 -0
  130. data/data/geocoding/en/994.dat +0 -0
  131. data/data/geocoding/en/994.txt +2 -2
  132. data/data/geocoding/en/995.dat +0 -0
  133. data/data/geocoding/en/995.txt +91 -0
  134. data/data/geocoding/es/52.dat +0 -0
  135. data/data/geocoding/es/52.txt +18 -16
  136. data/data/geocoding/es/54.dat +0 -0
  137. data/data/geocoding/es/54.txt +18 -3
  138. data/data/geocoding/es/56.dat +0 -0
  139. data/data/geocoding/es/56.txt +38 -1
  140. data/data/geocoding/es/57.dat +0 -0
  141. data/data/geocoding/es/57.txt +149 -0
  142. data/data/geocoding/es/58.dat +0 -0
  143. data/data/geocoding/es/58.txt +21 -12
  144. data/data/geocoding/fr/212.dat +0 -0
  145. data/data/geocoding/fr/212.txt +12 -4
  146. data/data/geocoding/fr/225.dat +0 -0
  147. data/data/geocoding/fr/225.txt +36 -12
  148. data/data/geocoding/fr/290.dat +0 -0
  149. data/data/geocoding/fr/290.txt +6 -1
  150. data/data/geocoding/fr/33.txt +115 -1
  151. data/data/geocoding/fr/352.dat +0 -0
  152. data/data/geocoding/fr/352.txt +0 -1
  153. data/data/geocoding/hy/374.dat +0 -0
  154. data/data/geocoding/hy/374.txt +0 -5
  155. data/data/geocoding/ja/81.dat +0 -0
  156. data/data/geocoding/ja/81.txt +9 -1
  157. data/data/geocoding/pt/238.dat +0 -0
  158. data/data/geocoding/pt/238.txt +3 -3
  159. data/data/geocoding/pt/55.dat +0 -0
  160. data/data/geocoding/pt/55.txt +1 -1
  161. data/data/geocoding/ru/374.dat +0 -0
  162. data/data/geocoding/ru/374.txt +0 -6
  163. data/data/geocoding/ru/7.dat +0 -0
  164. data/data/geocoding/ru/7.txt +92 -1
  165. data/data/geocoding/th/66.dat +0 -0
  166. data/data/geocoding/th/66.txt +4 -0
  167. data/data/telephone_number_data_file.dat +0 -0
  168. data/data/telephone_number_data_file.xml +4052 -1989
  169. data/data/timezones/map_data.dat +0 -0
  170. data/data/timezones/map_data.txt +287 -208
  171. data/lib/importers/geo_location_data_importer.rb +1 -1
  172. data/lib/telephone_number/country.rb +22 -9
  173. data/lib/telephone_number/version.rb +1 -1
  174. data/lib/telephone_number.rb +0 -1
  175. data/telephone_number.gemspec +1 -0
  176. metadata +47 -10
  177. data/lib/utilities/hash.rb +0 -47
@@ -8,7 +8,7 @@ module TelephoneNumber
8
8
  master_data = {}
9
9
  bin_file_path = "#{File.dirname(file_path)}/#{File.basename(file_path, '.txt')}.dat"
10
10
 
11
- File.open(file_path, 'r').each do |row|
11
+ File.open(file_path, 'r:UTF-8').each do |row|
12
12
  next if row.strip !~ /^[0-9]/
13
13
  number, location = row.split('|')
14
14
  master_data[number.strip] = location.strip
@@ -7,18 +7,18 @@ module TelephoneNumber
7
7
  MOBILE_TOKEN_COUNTRIES = { AR: '9' }.freeze
8
8
 
9
9
  def initialize(data_hash)
10
+ validations = data_hash.fetch(:validations, {}).dup
10
11
  @country_code = data_hash[:country_code]
11
12
  @country_id = data_hash[:id]
12
- @general_validation = NumberValidation.new(:general_desc, data_hash[:validations][:general_desc]) if data_hash.fetch(:validations, {})[:general_desc]
13
+ @general_validation = NumberValidation.new(:general_desc, validations[:general_desc]) if validations[:general_desc]
13
14
  @international_prefix = Regexp.new(data_hash[:international_prefix]) if data_hash[:international_prefix]
14
15
  @main_country_for_code = data_hash[:main_country_for_code] == 'true'
15
16
  @mobile_token = MOBILE_TOKEN_COUNTRIES[@country_id.to_sym]
16
17
  @national_prefix = data_hash[:national_prefix]
17
18
  @national_prefix_for_parsing = Regexp.new(data_hash[:national_prefix_for_parsing]) if data_hash[:national_prefix_for_parsing]
18
19
  @national_prefix_transform_rule = data_hash[:national_prefix_transform_rule]
19
- @validations = data_hash.fetch(:validations, {})
20
- .except(:general_desc, :area_code_optional)
21
- .map { |name, data| NumberValidation.new(name, data) }
20
+ @validations = validations.delete_if { |name, _| name == :general_desc || name == :area_code_optional }
21
+ .map { |name, data| NumberValidation.new(name, data) }
22
22
  @formats = data_hash.fetch(:formats, []).map { |format| NumberFormat.new(format, data_hash[:national_prefix_formatting_rule]) }
23
23
  end
24
24
 
@@ -52,11 +52,24 @@ module TelephoneNumber
52
52
  end
53
53
 
54
54
  def self.load_data
55
- data_file = "#{File.dirname(__FILE__)}/../../data/telephone_number_data_file.dat"
56
- main_data = Marshal.load(File.binread(data_file))
57
- override_data = {}
58
- override_data = Marshal.load(File.binread(TelephoneNumber.override_file)) if TelephoneNumber.override_file
59
- return main_data.deep_deep_merge!(override_data)
55
+ data_path = "#{File.dirname(__FILE__)}/../../data/telephone_number_data_file.dat"
56
+ main_data = Marshal.load(File.binread(data_path))
57
+ if TelephoneNumber.override_file
58
+ override_data = Marshal.load(File.binread(TelephoneNumber.override_file))
59
+ main_data = deep_merge(main_data, override_data)
60
+ end
61
+ main_data
62
+ end
63
+
64
+ def self.deep_merge(base_hash, other_hash)
65
+ other_hash.each do |key, value|
66
+ base_hash[key] = if base_hash[key].is_a?(Hash) && value.is_a?(Hash)
67
+ deep_merge(base_hash[key], value)
68
+ else
69
+ value
70
+ end
71
+ end
72
+ base_hash
60
73
  end
61
74
 
62
75
  def self.all_countries
@@ -1,3 +1,3 @@
1
1
  module TelephoneNumber
2
- VERSION = "1.4.6"
2
+ VERSION = "1.4.16"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'telephone_number/version'
2
- require 'utilities/hash'
3
2
  require 'active_model/telephone_number_validator' if defined?(ActiveModel)
4
3
  require 'forwardable'
5
4
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.4.0'
22
23
 
23
24
  spec.add_development_dependency 'bundler'
24
25
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telephone_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - MOBI Wireless Management
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2022-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email:
141
141
  - adam.fernung@mobiwm.com
142
142
  - josh.wetzel@mobiwm.com
@@ -150,6 +150,7 @@ files:
150
150
  - ".rubocop.yml"
151
151
  - ".ruby-version"
152
152
  - ".travis.yml"
153
+ - CHANGELOG.md
153
154
  - CODE_OF_CONDUCT.md
154
155
  - Gemfile
155
156
  - LICENSE
@@ -217,6 +218,8 @@ files:
217
218
  - data/geocoding/en/233.txt
218
219
  - data/geocoding/en/234.dat
219
220
  - data/geocoding/en/234.txt
221
+ - data/geocoding/en/236.dat
222
+ - data/geocoding/en/236.txt
220
223
  - data/geocoding/en/237.dat
221
224
  - data/geocoding/en/237.txt
222
225
  - data/geocoding/en/238.dat
@@ -373,6 +376,12 @@ files:
373
376
  - data/geocoding/en/58.txt
374
377
  - data/geocoding/en/592.dat
375
378
  - data/geocoding/en/592.txt
379
+ - data/geocoding/en/593.dat
380
+ - data/geocoding/en/593.txt
381
+ - data/geocoding/en/595.dat
382
+ - data/geocoding/en/595.txt
383
+ - data/geocoding/en/598.dat
384
+ - data/geocoding/en/598.txt
376
385
  - data/geocoding/en/599.dat
377
386
  - data/geocoding/en/599.txt
378
387
  - data/geocoding/en/60.dat
@@ -381,26 +390,40 @@ files:
381
390
  - data/geocoding/en/61.txt
382
391
  - data/geocoding/en/62.dat
383
392
  - data/geocoding/en/62.txt
393
+ - data/geocoding/en/63.dat
394
+ - data/geocoding/en/63.txt
384
395
  - data/geocoding/en/64.dat
385
396
  - data/geocoding/en/64.txt
386
397
  - data/geocoding/en/66.dat
387
398
  - data/geocoding/en/66.txt
399
+ - data/geocoding/en/670.dat
400
+ - data/geocoding/en/670.txt
401
+ - data/geocoding/en/672.dat
402
+ - data/geocoding/en/672.txt
388
403
  - data/geocoding/en/673.dat
389
404
  - data/geocoding/en/673.txt
390
405
  - data/geocoding/en/675.dat
391
406
  - data/geocoding/en/675.txt
392
407
  - data/geocoding/en/676.dat
393
408
  - data/geocoding/en/676.txt
409
+ - data/geocoding/en/678.dat
410
+ - data/geocoding/en/678.txt
394
411
  - data/geocoding/en/679.dat
395
412
  - data/geocoding/en/679.txt
396
413
  - data/geocoding/en/680.dat
397
414
  - data/geocoding/en/680.txt
398
415
  - data/geocoding/en/682.dat
399
416
  - data/geocoding/en/682.txt
417
+ - data/geocoding/en/685.dat
418
+ - data/geocoding/en/685.txt
400
419
  - data/geocoding/en/686.dat
401
420
  - data/geocoding/en/686.txt
402
421
  - data/geocoding/en/688.dat
403
422
  - data/geocoding/en/688.txt
423
+ - data/geocoding/en/689.dat
424
+ - data/geocoding/en/689.txt
425
+ - data/geocoding/en/690.dat
426
+ - data/geocoding/en/690.txt
404
427
  - data/geocoding/en/7.dat
405
428
  - data/geocoding/en/7.txt
406
429
  - data/geocoding/en/81.dat
@@ -409,6 +432,8 @@ files:
409
432
  - data/geocoding/en/82.txt
410
433
  - data/geocoding/en/84.dat
411
434
  - data/geocoding/en/84.txt
435
+ - data/geocoding/en/850.dat
436
+ - data/geocoding/en/850.txt
412
437
  - data/geocoding/en/86.dat
413
438
  - data/geocoding/en/86.txt
414
439
  - data/geocoding/en/880.dat
@@ -419,6 +444,8 @@ files:
419
444
  - data/geocoding/en/90.txt
420
445
  - data/geocoding/en/91.dat
421
446
  - data/geocoding/en/91.txt
447
+ - data/geocoding/en/92.dat
448
+ - data/geocoding/en/92.txt
422
449
  - data/geocoding/en/93.dat
423
450
  - data/geocoding/en/93.txt
424
451
  - data/geocoding/en/94.dat
@@ -427,12 +454,20 @@ files:
427
454
  - data/geocoding/en/95.txt
428
455
  - data/geocoding/en/960.dat
429
456
  - data/geocoding/en/960.txt
457
+ - data/geocoding/en/961.dat
458
+ - data/geocoding/en/961.txt
430
459
  - data/geocoding/en/962.dat
431
460
  - data/geocoding/en/962.txt
461
+ - data/geocoding/en/963.dat
462
+ - data/geocoding/en/963.txt
432
463
  - data/geocoding/en/966.dat
433
464
  - data/geocoding/en/966.txt
465
+ - data/geocoding/en/967.dat
466
+ - data/geocoding/en/967.txt
434
467
  - data/geocoding/en/968.dat
435
468
  - data/geocoding/en/968.txt
469
+ - data/geocoding/en/970.dat
470
+ - data/geocoding/en/970.txt
436
471
  - data/geocoding/en/971.dat
437
472
  - data/geocoding/en/971.txt
438
473
  - data/geocoding/en/972.dat
@@ -445,8 +480,12 @@ files:
445
480
  - data/geocoding/en/98.txt
446
481
  - data/geocoding/en/992.dat
447
482
  - data/geocoding/en/992.txt
483
+ - data/geocoding/en/993.dat
484
+ - data/geocoding/en/993.txt
448
485
  - data/geocoding/en/994.dat
449
486
  - data/geocoding/en/994.txt
487
+ - data/geocoding/en/995.dat
488
+ - data/geocoding/en/995.txt
450
489
  - data/geocoding/en/996.dat
451
490
  - data/geocoding/en/996.txt
452
491
  - data/geocoding/es/228.dat
@@ -596,13 +635,12 @@ files:
596
635
  - lib/telephone_number/parser.rb
597
636
  - lib/telephone_number/time_zone_detector.rb
598
637
  - lib/telephone_number/version.rb
599
- - lib/utilities/hash.rb
600
638
  - telephone_number.gemspec
601
639
  homepage: https://github.com/mobi/telephone_number
602
640
  licenses:
603
641
  - MIT
604
642
  metadata: {}
605
- post_install_message:
643
+ post_install_message:
606
644
  rdoc_options: []
607
645
  require_paths:
608
646
  - lib
@@ -610,16 +648,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
610
648
  requirements:
611
649
  - - ">="
612
650
  - !ruby/object:Gem::Version
613
- version: '0'
651
+ version: 2.4.0
614
652
  required_rubygems_version: !ruby/object:Gem::Requirement
615
653
  requirements:
616
654
  - - ">="
617
655
  - !ruby/object:Gem::Version
618
656
  version: '0'
619
657
  requirements: []
620
- rubyforge_project:
621
- rubygems_version: 2.6.14
622
- signing_key:
658
+ rubygems_version: 3.2.3
659
+ signing_key:
623
660
  specification_version: 4
624
661
  summary: Phone number validation
625
662
  test_files: []
@@ -1,47 +0,0 @@
1
- class Hash
2
- # Returns a new hash with +self+ and +other_hash+ merged recursively.
3
- #
4
- # h1 = { a: true, b: { c: [1, 2, 3] } }
5
- # h2 = { a: false, b: { x: [3, 4, 5] } }
6
- #
7
- # h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
8
- #
9
- # Like with Hash#merge in the standard library, a block can be provided
10
- # to merge values:
11
- #
12
- # h1 = { a: 100, b: 200, c: { c1: 100 } }
13
- # h2 = { b: 250, c: { c1: 200 } }
14
- # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
15
- # # => { a: 100, b: 450, c: { c1: 300 } }
16
- def deep_deep_merge(other_hash, &block)
17
- dup.deep_deep_merge!(other_hash, &block)
18
- end
19
-
20
- # Same as +deep_merge+, but modifies +self+.
21
- def deep_deep_merge!(other_hash, &block)
22
- other_hash.each_pair do |current_key, other_value|
23
- this_value = self[current_key]
24
-
25
- self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
26
- this_value.deep_deep_merge(other_value, &block)
27
- else
28
- if block_given? && key?(current_key)
29
- block.call(current_key, this_value, other_value)
30
- else
31
- other_value
32
- end
33
- end
34
- end
35
-
36
- self
37
- end
38
-
39
- def except(*keys)
40
- dup.except!(*keys)
41
- end
42
-
43
- def except!(*keys)
44
- keys.each { |key| delete(key) }
45
- self
46
- end
47
- end