tel_formatter 0.0.2 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae317999220de4a716655779151d9a7512484aa
4
- data.tar.gz: 4426b6b26c0629df467355f5f0de078dc5702c85
3
+ metadata.gz: 090357d69744f1057bd359325d3af1684cba4ab6
4
+ data.tar.gz: defeddce7d8ca4e24db3b224b05a3b528481e564
5
5
  SHA512:
6
- metadata.gz: b91d9c344a0f3f049562a92cbcbbcd75de545fc55c38951e82e075b48afeb0705e9c21db6d50ff1b9b7f6f1ca69f342cc6dffac9badc8840c49b1d82264e3f76
7
- data.tar.gz: f3af0e6a3d023635ca48e078cc25d63b172f4a488dfb10925d852ebe2d66508d3170bdd67ec2c19a66b6d67d78da515fc09d517753f620b7d8954e0597202ccf
6
+ metadata.gz: fc3d97320433f4e52e7c81dfee09f02f7736f18f6e67e6e8b83bed04a8cca0f22b9b0f7dd50d9286e778e287bbb039b2ea5d7a945f01aec8290d7ef431ccbdbe
7
+ data.tar.gz: 9231bf6ce4dba8d471ef9458c0423cec57111a909e05bff068bf47ef694205c45514e5374e7da15fff191419f79cb319fb4d42bdfab20cc297e9b0b94b96fc55
data/.rspec CHANGED
@@ -1 +1 @@
1
- -cfs
1
+ -c
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: bundle exec rake spec
2
+ script: bundle exec rspec
3
3
  rvm:
4
4
  - 2.1.0
5
5
  - 2.0.0
data/README.md CHANGED
@@ -28,8 +28,8 @@ Or install it yourself as:
28
28
  ```ruby
29
29
  require 'tel_formatter'
30
30
 
31
- Telformatter.format("0312345678") #=> "03-1234-5678"
32
- Telformatter.format("03.1235.5678") #=> "03-1234-5678"
31
+ TelFormatter.format("0312345678") #=> "03-1234-5678"
32
+ TelFormatter.format("03.1235.5678") #=> "03-1234-5678"
33
33
  ```
34
34
 
35
35
  ## Contributing
data/data/area_codes.txt CHANGED
@@ -8,13 +8,13 @@
8
8
  0134
9
9
  0135
10
10
  0136
11
+ 0137
11
12
  01372
12
13
  01374
13
- 0137
14
14
  01377
15
15
  0138
16
- 01392
17
16
  0139
17
+ 01392
18
18
  01397
19
19
  01398
20
20
  0142
@@ -25,11 +25,11 @@
25
25
  01457
26
26
  0146
27
27
  01466
28
+ 015
28
29
  0152
29
30
  0153
30
31
  0154
31
32
  01547
32
- 015
33
33
  0155
34
34
  01558
35
35
  0156
@@ -39,10 +39,10 @@
39
39
  01586
40
40
  01587
41
41
  0162
42
+ 0163
42
43
  01632
43
44
  01634
44
45
  01635
45
- 0163
46
46
  0164
47
47
  01648
48
48
  0165
@@ -52,27 +52,27 @@
52
52
  01658
53
53
  0166
54
54
  0167
55
+ 017
55
56
  0172
56
57
  0173
57
58
  0174
58
59
  0175
59
60
  0176
60
- 017
61
61
  0178
62
62
  0179
63
+ 018
63
64
  0182
64
65
  0183
65
66
  0184
66
67
  0185
67
68
  0186
68
69
  0187
69
- 018
70
+ 019
70
71
  0191
71
72
  0192
72
73
  0193
73
74
  0194
74
75
  0195
75
- 019
76
76
  0197
77
77
  0198
78
78
  022
@@ -83,18 +83,18 @@
83
83
  0226
84
84
  0228
85
85
  0229
86
+ 023
86
87
  0233
87
88
  0234
88
89
  0235
89
- 023
90
90
  0237
91
91
  0238
92
+ 024
92
93
  0240
93
94
  0241
94
95
  0242
95
96
  0243
96
97
  0244
97
- 024
98
98
  0246
99
99
  0247
100
100
  0248
@@ -106,9 +106,9 @@
106
106
  0257
107
107
  0258
108
108
  0259
109
+ 026
109
110
  0260
110
111
  0261
111
- 026
112
112
  0263
113
113
  0264
114
114
  0265
@@ -116,24 +116,24 @@
116
116
  0267
117
117
  0268
118
118
  0269
119
- 0270
120
119
  027
120
+ 0270
121
121
  0274
122
122
  0276
123
123
  0277
124
124
  0278
125
125
  0279
126
+ 028
126
127
  0280
127
128
  0282
128
129
  0283
129
130
  0284
130
131
  0285
131
- 028
132
132
  0287
133
133
  0288
134
134
  0289
135
- 0291
136
135
  029
136
+ 0291
137
137
  0293
138
138
  0294
139
139
  0295
@@ -141,24 +141,24 @@
141
141
  0297
142
142
  0299
143
143
  03
144
- 0422
144
+ 04
145
145
  042
146
+ 0422
146
147
  0428
147
- 04
148
148
  043
149
149
  0436
150
150
  0438
151
151
  0439
152
152
  044
153
153
  045
154
- 0460
155
154
  046
155
+ 0460
156
156
  0463
157
157
  0465
158
158
  0466
159
159
  0467
160
- 0470
161
160
  047
161
+ 0470
162
162
  0475
163
163
  0476
164
164
  0478
@@ -187,9 +187,9 @@
187
187
  0545
188
188
  0547
189
189
  0548
190
+ 055
190
191
  0550
191
192
  0551
192
- 055
193
193
  0553
194
194
  0554
195
195
  0555
@@ -248,26 +248,26 @@
248
248
  0748
249
249
  0749
250
250
  075
251
- 0761
252
251
  076
252
+ 0761
253
253
  0763
254
254
  0765
255
255
  0766
256
256
  0767
257
257
  0768
258
+ 077
258
259
  0770
259
260
  0771
260
261
  0772
261
262
  0773
262
263
  0774
263
- 077
264
264
  0776
265
265
  0778
266
266
  0779
267
267
  078
268
+ 079
268
269
  0790
269
270
  0791
270
- 079
271
271
  0794
272
272
  0795
273
273
  0796
@@ -291,12 +291,12 @@
291
291
  08387
292
292
  08388
293
293
  08396
294
+ 084
294
295
  0845
295
296
  0846
296
297
  0847
297
298
  08477
298
299
  0848
299
- 084
300
300
  08512
301
301
  08514
302
302
  0852
@@ -314,17 +314,18 @@
314
314
  0867
315
315
  0868
316
316
  0869
317
+ 087
317
318
  0875
318
319
  0877
319
- 087
320
320
  0879
321
+ 088
321
322
  0880
322
323
  0883
323
324
  0884
324
325
  0885
325
- 088
326
326
  0887
327
327
  0889
328
+ 089
328
329
  0892
329
330
  0893
330
331
  0894
@@ -332,7 +333,6 @@
332
333
  0896
333
334
  0897
334
335
  0898
335
- 089
336
336
  092
337
337
  0920
338
338
  093
@@ -346,13 +346,13 @@
346
346
  0948
347
347
  0949
348
348
  09496
349
+ 095
349
350
  0950
350
351
  0952
351
352
  0954
352
353
  0955
353
354
  0956
354
355
  0957
355
- 095
356
356
  0959
357
357
  096
358
358
  0964
@@ -361,10 +361,10 @@
361
361
  0967
362
362
  0968
363
363
  0969
364
+ 097
364
365
  0972
365
366
  0973
366
367
  0974
367
- 097
368
368
  0977
369
369
  0978
370
370
  0979
@@ -377,12 +377,13 @@
377
377
  0985
378
378
  0986
379
379
  0987
380
+ 099
380
381
  09912
381
382
  09913
382
- 099
383
383
  0993
384
384
  0994
385
385
  0995
386
386
  0996
387
387
  09969
388
388
  0997
389
+
@@ -1,3 +1,4 @@
1
+ 020
1
2
  050
2
3
  060
3
4
  070
File without changes
@@ -0,0 +1 @@
1
+ 0800
@@ -1,3 +1,3 @@
1
1
  module TelFormatter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/tel_formatter.rb CHANGED
@@ -3,11 +3,13 @@ require "tel_formatter/version"
3
3
 
4
4
  module TelFormatter
5
5
  AREA_CODES = File.read(File.expand_path("../../data/area_codes.txt", __FILE__)).split("\n").reverse
6
- SPECIAL_CODES = File.read(File.expand_path("../../data/special_codes.txt", __FILE__)).split("\n").reverse
6
+ SPECIAL_CODES_10 = File.read(File.expand_path("../../data/special_codes_10.txt", __FILE__)).split("\n").reverse
7
+ SPECIAL_CODES_11 = File.read(File.expand_path("../../data/special_codes_11.txt", __FILE__)).split("\n").reverse
7
8
  CELLPHONE_CODES = File.read(File.expand_path("../../data/cellphone_codes.txt", __FILE__)).split("\n").reverse
8
9
  AREA_CODE_REGEXP = /\A(#{AREA_CODES.join("|")})(\d{1,4})(\d{4})\Z/
9
- SPECIAL_CODE_REGEXP = /\A(#{SPECIAL_CODES.join("|")})(\d{6})\Z/
10
- CELLPHONE_CODE_REGEXP = /\A(#{CELLPHONE_CODES.join("|")})(\d{4})(\d{4})\Z/
10
+ SPECIAL_CODE_10_REGEXP = /\A(#{SPECIAL_CODES_10.join("|")})(\d{6})\Z/
11
+ SPECIAL_CODE_11_REGEXP = /\A(#{SPECIAL_CODES_11.join("|")})(\d{7})\Z/
12
+ CELLPHONE_CODE_REGEXP = /\A(#{CELLPHONE_CODES.join("|")})([1-9]\d{3})(\d{4})\Z/
11
13
 
12
14
  def self.format(tel)
13
15
  self.split(tel).join("-")
@@ -19,7 +21,7 @@ module TelFormatter
19
21
  when 10
20
22
  if AREA_CODE_REGEXP =~ tel
21
23
  return [$1, $2, $3]
22
- elsif SPECIAL_CODE_REGEXP =~ tel
24
+ elsif SPECIAL_CODE_10_REGEXP =~ tel
23
25
  return [$1, $2]
24
26
  else
25
27
  raise ArgumentError, "Invalid telephone number"
@@ -27,6 +29,8 @@ module TelFormatter
27
29
  when 11
28
30
  if CELLPHONE_CODE_REGEXP =~ tel
29
31
  return [$1, $2, $3]
32
+ elsif SPECIAL_CODE_11_REGEXP =~ tel
33
+ return [$1, $2]
30
34
  else
31
35
  raise ArgumentError, "Invalid telephone number"
32
36
  end
@@ -7,6 +7,22 @@ describe TelFormatter do
7
7
  tel = "0300000000"
8
8
  expect(TelFormatter.format(tel)).to eq("03-0000-0000")
9
9
  end
10
+
11
+ it "returns hyphenated telephone number based on split format 3 digit (eg Koganei, Tokyo) geo code" do
12
+ tel = "0429991111"
13
+ expect(TelFormatter.format(tel)).to eq("042-999-1111")
14
+ end
15
+
16
+ it "returns hyphenated telephone number based on split format 4 digit (eg Nishitama, Tokyo) geo code" do
17
+ tel = "0428991111"
18
+ expect(TelFormatter.format(tel)).to eq("0428-99-1111")
19
+ end
20
+
21
+ it "returns hyphenated telephone number based on split format 4 digit (eg Chofu, Tokyo) geo code" do
22
+ tel = "0422991111"
23
+ expect(TelFormatter.format(tel)).to eq("0422-99-1111")
24
+ # This should NOT be "042-299-1111"
25
+ end
10
26
  end
11
27
 
12
28
  describe ".split" do
@@ -21,9 +37,19 @@ describe TelFormatter do
21
37
  expect(TelFormatter.split(tel)).to eq(["01267", "0", "0000"])
22
38
  tel = "0120000000"
23
39
  expect(TelFormatter.split(tel)).to eq(["0120", "000000"])
24
- tel = "09000000000"
25
- expect(TelFormatter.split(tel)).to eq(["090", "0000", "0000"])
40
+ tel = "08099999999"
41
+ expect(TelFormatter.split(tel)).to eq(["080", "9999", "9999"])
42
+ tel = "08000000000"
43
+ expect(TelFormatter.split(tel)).to eq(["0800", "0000000"])
44
+
45
+ tel = "0429991111"
46
+ expect(TelFormatter.split(tel)).to eq(["042", "999", "1111"])
47
+ tel = "0428991111"
48
+ expect(TelFormatter.split(tel)).to eq(["0428", "99", "1111"])
49
+ tel = "0422991111"
50
+ expect(TelFormatter.split(tel)).to eq(["0422", "99", "1111"])
26
51
  end
52
+
27
53
  it "raises ArgumentError when Invalid number is given" do
28
54
  tel = "0200000000"
29
55
  expect { TelFormatter.split(tel) }.to raise_error(ArgumentError)
@@ -32,6 +58,7 @@ describe TelFormatter do
32
58
  tel = "050000000"
33
59
  expect { TelFormatter.split(tel) }.to raise_error(ArgumentError)
34
60
  end
61
+
35
62
  it "can handle Zenkaku chars and ignore non-numerical chars" do
36
63
  tel = "03−0000−0000"
37
64
  expect(TelFormatter.split(tel)).to eq(["03", "0000", "0000"])
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tel_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - iTakeshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description:
@@ -45,16 +45,17 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rspec
50
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
51
  - Gemfile
52
52
  - LICENSE.txt
53
53
  - README.md
54
54
  - Rakefile
55
55
  - data/area_codes.txt
56
56
  - data/cellphone_codes.txt
57
- - data/special_codes.txt
57
+ - data/special_codes_10.txt
58
+ - data/special_codes_11.txt
58
59
  - lib/tel_formatter.rb
59
60
  - lib/tel_formatter/version.rb
60
61
  - spec/spec_helper.rb
@@ -70,17 +71,17 @@ require_paths:
70
71
  - lib
71
72
  required_ruby_version: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - '>='
74
+ - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  requirements:
78
- - - '>='
79
+ - - ">="
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
83
  rubyforge_project:
83
- rubygems_version: 2.2.0
84
+ rubygems_version: 2.4.5
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: Format your telephone numbers