phony 2.18.23 → 2.19.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db67ba76e70a6de9c44cc306e4e07eac25c092b456b7a89fbbccd4f5298172b0
4
- data.tar.gz: f94e5219ec1808746635853d3cafdca6c91895330bf6b201b259301736b3e3eb
3
+ metadata.gz: cbadf1b4b8c2d79d7f32c069ee47175e879d57eaf582c93a6098efb068860945
4
+ data.tar.gz: 644bf8449040256b95af0a1d47bcc15ce0ff35b8dfbc0ee36dd72bdaec20bc4c
5
5
  SHA512:
6
- metadata.gz: 1119176e19553809a782b8300f263a4791bdb0cd45cf82356ba9dff7871ddc31866628de206734d830a6730eadd8cf1c0286aad0b8342ce95e0cbeb8383647ac
7
- data.tar.gz: 1e2eaf69ad9f1b5d2160c0ad7b1b720f54d51c9ad2fcf9708fb23bf43ef91ddb812571a5962e7808ba3c309657acfc5849b95ed788bad629a953a6cf5c3e016f
6
+ metadata.gz: 994d683a1954d9136d9ee1fe9086e328c14b547c12db01beaf004c81beafa5625ae02f131269cfe6c945fb9666d544318663fa34b35f9d40a611066025583a82
7
+ data.tar.gz: 43de3b0bf711cae8010b8b61c7c96b1ec89c88730044ae16acc68a6d866725e937811b33891a9663069f1f039d0c269fd1d1930413a168bce13957354694eba6
data/README.textile CHANGED
@@ -104,7 +104,7 @@ For example, when just loading the NANP CC, the retained memory usage is ~63kB.
104
104
 
105
105
  h2. List of Handled Countries
106
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.
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
108
 
109
109
  h2. License
110
110
 
@@ -269,7 +269,7 @@ service = [ # Not exhaustive.
269
269
  ]
270
270
 
271
271
  Phony.define do
272
- country '39', trunk('', :normalize => false) |
272
+ country '39', trunk('', normalize: false) |
273
273
  one_of(*service) >> split(3,3) |
274
274
  one_of(*mobile) >> split(3,4,-1..1) |
275
275
  one_of(*ndcs_2digit) >> split(4, 2..4) |
@@ -166,6 +166,7 @@ ndcs_with_6_subscriber_numbers = %w(
166
166
  422
167
167
  428
168
168
  436
169
+ 438
169
170
  439
170
171
  460
171
172
  463
@@ -281,7 +282,6 @@ ndcs_with_6_subscriber_numbers = %w(
281
282
  846
282
283
  847
283
284
  848
284
- 849
285
285
  852
286
286
  853
287
287
  854
@@ -361,7 +361,6 @@ ndcs_with_5_subscriber_numbers = %w(
361
361
  1374
362
362
  1377
363
363
  1392
364
- 1394
365
364
  1397
366
365
  1398
367
366
  1456
@@ -393,7 +392,6 @@ ndcs_with_5_subscriber_numbers = %w(
393
392
  8477
394
393
  8512
395
394
  8514
396
- 8636
397
395
  9496
398
396
  9802
399
397
  9912
@@ -403,12 +401,15 @@ ndcs_with_5_subscriber_numbers = %w(
403
401
 
404
402
  Phony.define do
405
403
  country '81',
406
- trunk('0') |
407
- one_of('20', '50', '60', '70', '90') >> split(4,4) | # mobile, VoIP telephony
404
+ trunk('0', normalize: true, format: true, split: true) |
405
+ one_of(%w(20 50 60 70 90)) >> split(4,4) | # mobile, VoIP telephony
408
406
  one_of(ndcs_with_5_subscriber_numbers) >> split(1,4) |
409
407
  one_of(ndcs_with_6_subscriber_numbers) >> split(2,4) |
410
408
  one_of(%w(120)) >> split(3,3) | # freephone
411
- one_of(%w(120 800)) >> split(3,4) | # freephone
409
+ one_of(%w(800)) >> split(3,4) | # freephone
410
+ one_of(%w(180 570)) >> split(3,3) | # Tele-gong/Tele-dome, Navi-dial
411
+ one_of(%w(170 990)) >> split(2,4) | # Dengon-dial, Dial Q2 (discontinued)
412
+ one_of(%w(80)) >> split(4,4) | # mobile
412
413
  one_of(ndcs_with_7_subscriber_numbers) >> split(3,4) |
413
414
  one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
414
415
  # TODO: 91(NDC) N(S)N length: 5-13 - Non-geographic number (Direct subscriber telephone service (legacy))
data/lib/phony/country.rb CHANGED
@@ -156,10 +156,12 @@ module Phony
156
156
  #
157
157
  # In some cases it doesn't, like Italy.
158
158
  #
159
- def normalize national_number
159
+ # Note: Options such as CC
160
+ #
161
+ def normalize national_number, options = {}
160
162
  clean! national_number
161
163
  normalized = @codes.reduce national_number do |number, code|
162
- result = code.normalize number
164
+ result = code.normalize number, options
163
165
  break result if result
164
166
  number
165
167
  end
@@ -66,7 +66,7 @@ module Phony
66
66
  country, cc, number = partial_split number
67
67
  country
68
68
  end
69
- number = country.normalize number
69
+ number = country.normalize number, cc: cc
70
70
  countrify! number, cc
71
71
  end
72
72
 
@@ -26,7 +26,7 @@ module Phony
26
26
  #
27
27
  # Note: Some cases, like Italy, don't remove the relative zero.
28
28
  #
29
- def normalize national_number
29
+ def normalize national_number, options = {}
30
30
  national_number.gsub(/\A0+/, EMPTY_STRING)
31
31
  end
32
32
 
@@ -6,9 +6,9 @@ module Phony
6
6
  # * code: The trunk code, e.g. 0.
7
7
  #
8
8
  # Options:
9
- # * normalize: Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
10
- # * split: Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
11
- # * format: Add the trunk code when formatting (passing `false` will not add it).
9
+ # * normalize: [true (default), false] Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
10
+ # * split: [true, false (default)] Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
11
+ # * format: [true (default), false] Add the trunk code when formatting (passing `false` will not add it).
12
12
  #
13
13
  def initialize code, options = {}
14
14
  @code = code
@@ -35,8 +35,8 @@ module Phony
35
35
 
36
36
  # Normalize normalizes the given national number.
37
37
  #
38
- def normalize national_number
39
- national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
38
+ def normalize national_number, options = {}
39
+ national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize && options[:cc]
40
40
  return national_number
41
41
  end
42
42
 
@@ -484,6 +484,8 @@ describe 'country descriptions' do
484
484
  it_splits '817012345678', %w(81 70 1234 5678) # PHS
485
485
  it_splits '818012345678', %w(81 80 1234 5678) # Cellular
486
486
  it_splits '819012345678', %w(81 90 1234 5678) # Cellular
487
+ it_splits '810570123456', %w(81 570 123 456) # Navi-dial
488
+ it_splits '810180123456', %w(81 180 123 456) # Tele-gong/Tele-dome
487
489
  end
488
490
  describe 'Kenya' do
489
491
  it_splits '254201234567', ['254', '20', '1234567'] # Nairobi
@@ -43,6 +43,18 @@ describe Phony::Country do
43
43
  Phony.normalize('+378903549').should == '3780549903549'
44
44
  end
45
45
  end
46
+ describe 'Japan' do
47
+ it 'normalizes correctly' do
48
+ Phony.normalize('+81-03-1234-5634').should == '81312345634'
49
+ Phony.normalize('03-1234-5634', cc: '81').should == '81312345634'
50
+ end
51
+ it 'formats correctly' do
52
+ Phony.format('81312345634').should == '+81-3-1234-5634'
53
+ end
54
+ it 'splits correctly' do
55
+ Phony.split('81312345634').should == %w(81 3 1234 5634)
56
+ end
57
+ end
46
58
  end
47
59
 
48
60
  context "without special cases (with switzerland)" do
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phony::TrunkCode do
4
+
5
+ describe '#format' do
6
+ it 'is correct' do
7
+ code = described_class.new('0')
8
+ expect(code.format('%s %s')).to eq '0'
9
+ end
10
+ it 'is correct' do
11
+ code = described_class.new('0', format: true)
12
+ expect(code.format('%s %s')).to eq '0'
13
+ end
14
+ it 'is correct' do
15
+ code = described_class.new('0', format: false)
16
+ expect(code.format('%s %s')).to eq nil
17
+ end
18
+ it 'is correct' do
19
+ code = described_class.new('06')
20
+ expect(code.format('%s %s')).to eq '06'
21
+ end
22
+ it 'is correct' do
23
+ code = described_class.new('06', format: true)
24
+ expect(code.format('%s %s')).to eq '06'
25
+ end
26
+ it 'is correct' do
27
+ code = described_class.new('06', format: false)
28
+ expect(code.format('%s %s')).to eq nil
29
+ end
30
+ end
31
+
32
+ describe '#normalize' do
33
+ it 'is correct' do
34
+ code = described_class.new('0')
35
+ expect(code.normalize('0123')).to eq '0123'
36
+ end
37
+ it 'is correct' do
38
+ code = described_class.new('0', normalize: true)
39
+ expect(code.normalize('0123')).to eq '0123'
40
+ end
41
+ it 'is correct' do
42
+ code = described_class.new('0', normalize: false)
43
+ expect(code.normalize('0123')).to eq '0123'
44
+ end
45
+ it 'is correct' do
46
+ code = described_class.new('06')
47
+ expect(code.normalize('06123')).to eq '06123'
48
+ end
49
+ it 'is correct' do
50
+ code = described_class.new('06', normalize: true)
51
+ expect(code.normalize('06123')).to eq '06123'
52
+ end
53
+ it 'is correct' do
54
+ code = described_class.new('06', normalize: false)
55
+ expect(code.normalize('0123')).to eq '0123'
56
+ end
57
+ end
58
+
59
+ describe '#split' do
60
+ it 'is correct' do
61
+ code = described_class.new('0')
62
+ expect(code.split('0123')).to eq [code, '0123']
63
+ end
64
+ it 'is correct' do
65
+ code = described_class.new('0', split: true)
66
+ expect(code.split('0123')).to eq [code, '123']
67
+ end
68
+ it 'is correct' do
69
+ code = described_class.new('0', split: false)
70
+ expect(code.split('0123')).to eq [code, '0123']
71
+ end
72
+ it 'is correct' do
73
+ code = described_class.new('06')
74
+ expect(code.split('06123')).to eq [code, '06123']
75
+ end
76
+ it 'is correct' do
77
+ code = described_class.new('06', split: true)
78
+ expect(code.split('06123')).to eq [code, '123']
79
+ end
80
+ it 'is correct' do
81
+ code = described_class.new('06', split: false)
82
+ expect(code.split('06123')).to eq [code, '06123']
83
+ end
84
+ end
85
+ 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.18.23
4
+ version: 2.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-06-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
@@ -93,6 +93,7 @@ files:
93
93
  - spec/lib/phony/national_splitters/none_spec.rb
94
94
  - spec/lib/phony/national_splitters/regex_spec.rb
95
95
  - spec/lib/phony/national_splitters/variable_spec.rb
96
+ - spec/lib/phony/trunk_code_spec.rb
96
97
  - spec/lib/phony/vanity_spec.rb
97
98
  - spec/lib/phony_spec.rb
98
99
  homepage: https://github.com/floere/phony
@@ -121,6 +122,7 @@ summary: Fast international phone number (E164 standard) normalizing, splitting
121
122
  formatting.
122
123
  test_files:
123
124
  - spec/lib/phony_spec.rb
125
+ - spec/lib/phony/trunk_code_spec.rb
124
126
  - spec/lib/phony/country_spec.rb
125
127
  - spec/lib/phony/national_code_spec.rb
126
128
  - spec/lib/phony/countries_spec.rb