tel_formatter 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d837fc21414c13d2207ea8752509cfb6aa388897
4
+ data.tar.gz: 972b2fba6538ad8312113880e9e910e27b9f6755
5
+ SHA512:
6
+ metadata.gz: 49b9e2dce45df6d84deeee2de48c6ab69cdca38def2da055c69d644c1dccc0ba9c8257f1e23b6c7c7a2622f8ac46e54bac709af48a0355082aad3507c014aa95
7
+ data.tar.gz: e664f68a8cfdd1ed649d3df6551cdd1ebf2976e041d83e0dddbbf04af8297443015dfc70cab45c33100fdc9ab46fa8337febc12a6ad9e3298f5815018ce85aa5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -cfs
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ script: bundle exec rake spec
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem"s dependencies in tel_formatter.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rspec"
8
+ gem "coveralls", require: false
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 iTakeshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # TelFormatter
2
+
3
+ [![Build Status](https://travis-ci.org/iTakeshi/tel_formatter.png?branch=master)](https://travis-ci.org/iTakeshi/tel_formatter)
4
+ [![Coverage Status](https://coveralls.io/repos/iTakeshi/tel_formatter/badge.png)](https://coveralls.io/r/iTakeshi/tel_formatter)
5
+
6
+ Format your telephone numbers.
7
+
8
+ ## Notice
9
+
10
+ I am not assuming this gem will be used outside Japan.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'tel_formatter'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install tel_formatter
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ Telformatter.format("0312345678") #=> "03-1234-5678"
30
+ Telformatter.format("03.1235.5678") #=> "03-1234-5678"
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( http://github.com/iTakeshi/tel_formatter/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Write spec and run tests (`bundle exec rspec`)
39
+ 5. Push to the branch (`git push origin my-new-feature`)
40
+ 6. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = "spec/**/*_spec.rb"
7
+ spec.rspec_opts = ["-cfs"]
8
+ end
9
+ rescue LoadError => e
10
+ end
@@ -0,0 +1,388 @@
1
+ 011
2
+ 0123
3
+ 0124
4
+ 0125
5
+ 0126
6
+ 01267
7
+ 0133
8
+ 0134
9
+ 0135
10
+ 0136
11
+ 01372
12
+ 01374
13
+ 0137
14
+ 01377
15
+ 0138
16
+ 01392
17
+ 0139
18
+ 01397
19
+ 01398
20
+ 0142
21
+ 0143
22
+ 0144
23
+ 0145
24
+ 01456
25
+ 01457
26
+ 0146
27
+ 01466
28
+ 0152
29
+ 0153
30
+ 0154
31
+ 01547
32
+ 015
33
+ 0155
34
+ 01558
35
+ 0156
36
+ 01564
37
+ 0157
38
+ 0158
39
+ 01586
40
+ 01587
41
+ 0162
42
+ 01632
43
+ 01634
44
+ 01635
45
+ 0163
46
+ 0164
47
+ 01648
48
+ 0165
49
+ 01654
50
+ 01655
51
+ 01656
52
+ 01658
53
+ 0166
54
+ 0167
55
+ 0172
56
+ 0173
57
+ 0174
58
+ 0175
59
+ 0176
60
+ 017
61
+ 0178
62
+ 0179
63
+ 0182
64
+ 0183
65
+ 0184
66
+ 0185
67
+ 0186
68
+ 0187
69
+ 018
70
+ 0191
71
+ 0192
72
+ 0193
73
+ 0194
74
+ 0195
75
+ 019
76
+ 0197
77
+ 0198
78
+ 022
79
+ 0220
80
+ 0223
81
+ 0224
82
+ 0225
83
+ 0226
84
+ 0228
85
+ 0229
86
+ 0233
87
+ 0234
88
+ 0235
89
+ 023
90
+ 0237
91
+ 0238
92
+ 0240
93
+ 0241
94
+ 0242
95
+ 0243
96
+ 0244
97
+ 024
98
+ 0246
99
+ 0247
100
+ 0248
101
+ 025
102
+ 0250
103
+ 0254
104
+ 0255
105
+ 0256
106
+ 0257
107
+ 0258
108
+ 0259
109
+ 0260
110
+ 0261
111
+ 026
112
+ 0263
113
+ 0264
114
+ 0265
115
+ 0266
116
+ 0267
117
+ 0268
118
+ 0269
119
+ 0270
120
+ 027
121
+ 0274
122
+ 0276
123
+ 0277
124
+ 0278
125
+ 0279
126
+ 0280
127
+ 0282
128
+ 0283
129
+ 0284
130
+ 0285
131
+ 028
132
+ 0287
133
+ 0288
134
+ 0289
135
+ 0291
136
+ 029
137
+ 0293
138
+ 0294
139
+ 0295
140
+ 0296
141
+ 0297
142
+ 0299
143
+ 03
144
+ 0422
145
+ 042
146
+ 0428
147
+ 04
148
+ 043
149
+ 0436
150
+ 0438
151
+ 0439
152
+ 044
153
+ 045
154
+ 0460
155
+ 046
156
+ 0463
157
+ 0465
158
+ 0466
159
+ 0467
160
+ 0470
161
+ 047
162
+ 0475
163
+ 0476
164
+ 0478
165
+ 0479
166
+ 048
167
+ 0480
168
+ 049
169
+ 0493
170
+ 0494
171
+ 0495
172
+ 04992
173
+ 04994
174
+ 04996
175
+ 04998
176
+ 052
177
+ 053
178
+ 0531
179
+ 0532
180
+ 0533
181
+ 0536
182
+ 0537
183
+ 0538
184
+ 0539
185
+ 054
186
+ 0544
187
+ 0545
188
+ 0547
189
+ 0548
190
+ 0550
191
+ 0551
192
+ 055
193
+ 0553
194
+ 0554
195
+ 0555
196
+ 0556
197
+ 0557
198
+ 0558
199
+ 0561
200
+ 0562
201
+ 0563
202
+ 0564
203
+ 0565
204
+ 0566
205
+ 0567
206
+ 0568
207
+ 0569
208
+ 0572
209
+ 0573
210
+ 0574
211
+ 0575
212
+ 0576
213
+ 05769
214
+ 0577
215
+ 0578
216
+ 058
217
+ 0581
218
+ 0584
219
+ 0585
220
+ 0586
221
+ 0587
222
+ 059
223
+ 0594
224
+ 0595
225
+ 0596
226
+ 0597
227
+ 05979
228
+ 0598
229
+ 0599
230
+ 06
231
+ 072
232
+ 0721
233
+ 0725
234
+ 073
235
+ 0735
236
+ 0736
237
+ 0737
238
+ 0738
239
+ 0739
240
+ 0740
241
+ 0742
242
+ 0743
243
+ 0744
244
+ 0745
245
+ 0746
246
+ 07468
247
+ 0747
248
+ 0748
249
+ 0749
250
+ 075
251
+ 0761
252
+ 076
253
+ 0763
254
+ 0765
255
+ 0766
256
+ 0767
257
+ 0768
258
+ 0770
259
+ 0771
260
+ 0772
261
+ 0773
262
+ 0774
263
+ 077
264
+ 0776
265
+ 0778
266
+ 0779
267
+ 078
268
+ 0790
269
+ 0791
270
+ 079
271
+ 0794
272
+ 0795
273
+ 0796
274
+ 0797
275
+ 0798
276
+ 0799
277
+ 082
278
+ 0820
279
+ 0823
280
+ 0824
281
+ 0826
282
+ 0827
283
+ 0829
284
+ 083
285
+ 0833
286
+ 0834
287
+ 0835
288
+ 0836
289
+ 0837
290
+ 0838
291
+ 08387
292
+ 08388
293
+ 08396
294
+ 0845
295
+ 0846
296
+ 0847
297
+ 08477
298
+ 0848
299
+ 084
300
+ 08512
301
+ 08514
302
+ 0852
303
+ 0853
304
+ 0854
305
+ 0855
306
+ 0856
307
+ 0857
308
+ 0858
309
+ 0859
310
+ 086
311
+ 0863
312
+ 0865
313
+ 0866
314
+ 0867
315
+ 0868
316
+ 0869
317
+ 0875
318
+ 0877
319
+ 087
320
+ 0879
321
+ 0880
322
+ 0883
323
+ 0884
324
+ 0885
325
+ 088
326
+ 0887
327
+ 0889
328
+ 0892
329
+ 0893
330
+ 0894
331
+ 0895
332
+ 0896
333
+ 0897
334
+ 0898
335
+ 089
336
+ 092
337
+ 0920
338
+ 093
339
+ 0930
340
+ 0940
341
+ 0942
342
+ 0943
343
+ 0944
344
+ 0946
345
+ 0947
346
+ 0948
347
+ 0949
348
+ 09496
349
+ 0950
350
+ 0952
351
+ 0954
352
+ 0955
353
+ 0956
354
+ 0957
355
+ 095
356
+ 0959
357
+ 096
358
+ 0964
359
+ 0965
360
+ 0966
361
+ 0967
362
+ 0968
363
+ 0969
364
+ 0972
365
+ 0973
366
+ 0974
367
+ 097
368
+ 0977
369
+ 0978
370
+ 0979
371
+ 098
372
+ 0980
373
+ 09802
374
+ 0982
375
+ 0983
376
+ 0984
377
+ 0985
378
+ 0986
379
+ 0987
380
+ 09912
381
+ 09913
382
+ 099
383
+ 0993
384
+ 0994
385
+ 0995
386
+ 0996
387
+ 09969
388
+ 0997
@@ -0,0 +1,5 @@
1
+ 050
2
+ 060
3
+ 070
4
+ 080
5
+ 090
@@ -0,0 +1,5 @@
1
+ 0120
2
+ 0990
3
+ 0180
4
+ 0570
5
+ 0170
@@ -0,0 +1,3 @@
1
+ module TelFormatter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "nkf"
2
+ require "tel_formatter/version"
3
+
4
+ module TelFormatter
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
7
+ CELLPHONE_CODES = File.read(File.expand_path("../../data/cellphone_codes.txt", __FILE__)).split("\n").reverse
8
+ 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/
11
+
12
+ def self.format(tel)
13
+ self.split(tel).join("-")
14
+ end
15
+
16
+ def self.split(tel)
17
+ tel = self.preprocess(tel)
18
+ case tel.length
19
+ when 10
20
+ if AREA_CODE_REGEXP =~ tel
21
+ return [$1, $2, $3]
22
+ elsif SPECIAL_CODE_REGEXP =~ tel
23
+ return [$1, $2]
24
+ else
25
+ raise ArgumentError, "Invalid telephone number"
26
+ end
27
+ when 11
28
+ if CELLPHONE_CODE_REGEXP =~ tel
29
+ return [$1, $2, $3]
30
+ else
31
+ raise ArgumentError, "Invalid telephone number"
32
+ end
33
+ else
34
+ raise ArgumentError, "Invalid telephone number"
35
+ end
36
+ end
37
+
38
+ def self.preprocess(tel)
39
+ NKF.nkf("-m0Z0 -w", tel).split("").select { |c| /\d/ =~ c }.join
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'rspec'
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+ require "tel_formatter"
3
+
4
+ describe TelFormatter do
5
+ describe ".format" do
6
+ it "returns hyphenated telephone number" do
7
+ tel = "0300000000"
8
+ expect(TelFormatter.format(tel)).to eq("03-0000-0000")
9
+ end
10
+ end
11
+
12
+ describe ".split" do
13
+ it "splits telephone number into 2 or 3 blocks" do
14
+ tel = "0300000000"
15
+ expect(TelFormatter.split(tel)).to eq(["03", "0000", "0000"])
16
+ tel = "0110000000"
17
+ expect(TelFormatter.split(tel)).to eq(["011", "000", "0000"])
18
+ tel = "0123000000"
19
+ expect(TelFormatter.split(tel)).to eq(["0123", "00", "0000"])
20
+ tel = "0126700000"
21
+ expect(TelFormatter.split(tel)).to eq(["01267", "0", "0000"])
22
+ tel = "0120000000"
23
+ expect(TelFormatter.split(tel)).to eq(["0120", "000000"])
24
+ tel = "09000000000"
25
+ expect(TelFormatter.split(tel)).to eq(["090", "0000", "0000"])
26
+ end
27
+ it "raises ArgumentError when Invalid number is given" do
28
+ tel = "0200000000"
29
+ expect { TelFormatter.split(tel) }.to raise_error(ArgumentError)
30
+ tel = "04000000000"
31
+ expect { TelFormatter.split(tel) }.to raise_error(ArgumentError)
32
+ tel = "050000000"
33
+ expect { TelFormatter.split(tel) }.to raise_error(ArgumentError)
34
+ end
35
+ it "can handle Zenkaku chars and ignore non-numerical chars" do
36
+ tel = "03−0000−0000"
37
+ expect(TelFormatter.split(tel)).to eq(["03", "0000", "0000"])
38
+ end
39
+ end
40
+
41
+ describe ".preprocess" do
42
+ it "converts Zenkaku chars to Hankaku, and excludes any non-numerical chars" do
43
+ tel = "03−0000−0000"
44
+ expect(TelFormatter.preprocess(tel)).to eq("0300000000")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tel_formatter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tel_formatter"
8
+ spec.version = TelFormatter::VERSION
9
+ spec.authors = ["iTakeshi"]
10
+ spec.email = ["takeshi.ito.doraemon@gmail.com"]
11
+ spec.summary = %q{Format your telephone numbers}
12
+ spec.homepage = "https://github.com/iTakeshi/tel_formatter"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "rake"
21
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tel_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - iTakeshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - takeshi.ito.doraemon@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .travis.yml
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - data/area_codes.txt
56
+ - data/cellphone_codes.txt
57
+ - data/special_codes.txt
58
+ - lib/tel_formatter.rb
59
+ - lib/tel_formatter/version.rb
60
+ - spec/spec_helper.rb
61
+ - spec/tel_formatter_spec.rb
62
+ - tel_formatter.gemspec
63
+ homepage: https://github.com/iTakeshi/tel_formatter
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.0
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Format your telephone numbers
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/tel_formatter_spec.rb