data_maker 2.0.0

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: 21a5abed170712d37dc867e158911d7b66ab5987
4
+ data.tar.gz: 83a73e740fb8e9ff61692708a3b150435b6b35bc
5
+ SHA512:
6
+ metadata.gz: 8e3e6c85a7f6c7dd28f64da3d0d80979400955641639c2db2138ffd3843e8e2ec8871b31cdb75c08e1d4ac8e037ff54372a869fa9c277c13509ffbf7821552bd
7
+ data.tar.gz: ddda374aa9c0e293ab310ca3e677cd37739565e90ec2d26b7e7dfe193b4559cb8768e6c1db4425afcb5936513c5bd00924a193bb9e02160a16cffa634cb905be
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Kareem Gan
2
+ Copyright (c) 2013 Emmanuel Oga
3
+ Copyright (c) 2007 Benjamin Curtis
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,34 @@
1
+ ## Data Maker
2
+
3
+ [![Gem Version][GV img]][Gem Version]
4
+ [![Build Status][BS img]][Build Status]
5
+ [![Dependency Status][DS img]][Dependency Status]
6
+ [![Code Climate][CC img]][Code Climate]
7
+ [![Coverage Status][CS img]][Coverage Status]
8
+
9
+ ## Description
10
+
11
+ This is a fork of faker and ffaker gem. This will include a more robust
12
+ generation of data for Chinese related records.
13
+
14
+ I made this intentionally so I could keep adding without the need for the author
15
+ to constantly be annoyed with my pull requests.
16
+
17
+ [Gem Version]: https://rubygems.org/gems/data_maker
18
+ [Build Status]: https://travis-ci.org/magicalbanana/data_maker
19
+ [travis pull requests]: https://travis-ci.org/magicalbanana/data_maker/pull_requests
20
+ [Dependency Status]: https://gemnasium.com/magicalbanana/data_maker
21
+ [Code Climate]: https://codeclimate.com/github/magicalbanana/data_maker
22
+ [Coverage Status]: https://coveralls.io/r/magicalbanana/data_maker
23
+
24
+ [GV img]: https://badge.fury.io/rb/data_maker.svg
25
+ [BS img]: https://travis-ci.org/magicalbanana/data_maker.svg
26
+ [DS img]: https://gemnasium.com/magicalbanana/data_maker.svg
27
+ [CC img]: https://codeclimate.com/github/magicalbanana/data_maker.svg
28
+ [CS img]: https://coveralls.io/repos/magicalbanana/data_maker/badge.svg?branch=master
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2015 Kareem Gan
33
+ Copyright (c) 2013 Emmanuel Oga
34
+ Copyright (c) 2007 Benjamin Curtis
data/Rakefile ADDED
@@ -0,0 +1,139 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ require 'rspec/core/rake_task'
47
+
48
+ RSpec::Core::RakeTask.new(:spec) do |t|
49
+ ENV["COVERAGE"] = "true"
50
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
51
+ t.rspec_opts = '--format documentation'
52
+ end
53
+
54
+ task :default => :test
55
+ task :test => :spec
56
+
57
+ desc "Open an irb session preloaded with this library"
58
+ task :console do
59
+ sh "pry -I ./lib/ -rubygems -r ./lib/#{name}.rb"
60
+ end
61
+
62
+ #############################################################################
63
+ #
64
+ # Custom tasks (add your own tasks here)
65
+ #
66
+ #############################################################################
67
+
68
+ begin
69
+ require 'yard'
70
+ YARD::Rake::YardocTask.new
71
+ rescue LoadError
72
+ task :yardoc do
73
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
74
+ end
75
+ end
76
+
77
+ #############################################################################
78
+ #
79
+ # Packaging tasks
80
+ #
81
+ #############################################################################
82
+
83
+ task :release => :build do
84
+ unless `git branch` =~ /^\* master$/
85
+ puts "You must be on the master branch to release!"
86
+ exit!
87
+ end
88
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
89
+ sh "git tag v#{version}"
90
+ sh "git push origin master"
91
+ sh "git push --tags"
92
+ sh "gem push pkg/#{name}-#{version}.gem"
93
+ end
94
+
95
+ task :build => :gemspec do
96
+ sh "mkdir -p pkg"
97
+ sh "gem build #{gemspec_file}"
98
+ sh "mv #{gem_file} pkg"
99
+ end
100
+
101
+ task :gemspec => :validate do
102
+ # read spec file and split out manifest section
103
+ spec = File.read(gemspec_file)
104
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
105
+
106
+ # replace name version and date
107
+ replace_header(head, :name)
108
+ replace_header(head, :version)
109
+ replace_header(head, :date)
110
+ #comment this out if your rubyforge_project has a different name
111
+ replace_header(head, :rubyforge_project)
112
+
113
+ # determine file list from git ls-files
114
+ files = `git ls-files`.
115
+ split("\n").
116
+ sort.
117
+ reject { |file| file =~ /^\./ }.
118
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
119
+ map { |file| " #{file}" }.
120
+ join("\n")
121
+
122
+ # piece file back together and write
123
+ manifest = " gem.files = %w[\n#{files}\n ]\n"
124
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
125
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
126
+ puts "Updated #{gemspec_file}"
127
+ end
128
+
129
+ task :validate do
130
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
131
+ unless libfiles.empty?
132
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
133
+ exit!
134
+ end
135
+ unless Dir['VERSION*'].empty?
136
+ puts "A `VERSION` file at root level violates Gem best practices."
137
+ exit!
138
+ end
139
+ end
@@ -0,0 +1,64 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'data_maker'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'data_maker'
8
+ gem.version = DataMaker::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = 'Kareem Gan'
11
+ gem.email = 'kareemgan@gmail.com'
12
+ gem.summary = 'Data generator gem for aiding in development and testing for applications.'
13
+ gem.homepage = 'https://github.com/magicalbanana/data_maker'
14
+ gem.license = 'MIT'
15
+
16
+ gem.description = <<-EOT
17
+ Data generation using yml files from different sources. This was originally forked from faker and ffaker gem
18
+ respecetively.
19
+ EOT
20
+
21
+ gem.extra_rdoc_files = ['README.md']
22
+ # gem.bindir = 'bin'
23
+ # gem.executables << 'data_maker-console'
24
+
25
+ gem.add_development_dependency 'simplecov', '~> 0.8.2', '>= 0.8.2'
26
+ gem.add_development_dependency 'coveralls', '~> 0.7.0', '>= 0.7.0'
27
+ gem.add_development_dependency 'rake', '10.1.1', '>= 10.1.1'
28
+ gem.add_development_dependency 'rspec', '~> 3.1.0', '>= 3.1.0'
29
+ gem.add_development_dependency 'pry-byebug', '~> 3.1.0', '>= 3.1.0'
30
+ gem.add_development_dependency 'pry-rescue', '~> 1.4.1', '>= 1.4.1'
31
+ gem.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.1', '>= 0.4.9.1'
32
+
33
+ gem.add_runtime_dependency 'pry', '~> 0.10.1', '>= 0.10.1'
34
+
35
+ gem.post_install_message = "To test out the generator execute command data_maker-console"
36
+
37
+ gem.required_ruby_version = '>= 1.9.3'
38
+
39
+ gem.require_path = 'lib'
40
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
41
+
42
+ # = MANIFEST =
43
+ gem.files = %w[
44
+ Gemfile
45
+ LICENSE
46
+ README.md
47
+ Rakefile
48
+ data_maker.gemspec
49
+ lib/data_maker.rb
50
+ lib/data_maker/china/phone_number.rb
51
+ lib/data_maker/data/china/phone_number/landline_phone_prefixes
52
+ lib/data_maker/data/china/phone_number/mobile_phone_prefixes
53
+ lib/data_maker/utilities/array_utilities.rb
54
+ lib/data_maker/utilities/module_utilities.rb
55
+ lib/data_maker/validators/chinese_phone_number.rb
56
+ spec/lib/data_maker/china/phone_number_spec.rb
57
+ spec/lib/data_maker/data_maker_spec.rb
58
+ spec/lib/data_maker/support/matchers/phone_number_matcher.rb
59
+ spec/lib/data_maker/utilities/array_utilities_spec.rb
60
+ spec/lib/data_maker/utilities/module_utilities_spec.rb
61
+ spec/spec_helper.rb
62
+ ]
63
+ # = MANIFEST =
64
+ end
@@ -0,0 +1,101 @@
1
+ module DataMaker
2
+ module China
3
+ module PhoneNumber
4
+ extend ModuleUtilities
5
+
6
+ def self.mobile
7
+ number = PhoneNumberGenerator.new("mobile")
8
+ number.generate
9
+ end
10
+
11
+ def self.landline
12
+ number = PhoneNumberGenerator.new(LANDLINE_FORMAT)
13
+ number.generate
14
+ end
15
+
16
+ def self.phone_number
17
+ end
18
+
19
+ class PhoneNumberGenerator
20
+ def initialize(format)
21
+ self.format = format
22
+ end
23
+
24
+ def mobile_prefix
25
+ prefix = DataMaker::China::PhoneNumber::MOBILE_PHONE_PREFIXES.sample
26
+ raise StandardError, "You're file is empty!" if prefix.length == 0
27
+ prefix
28
+ end
29
+
30
+ def landline_prefix
31
+ prefix = DataMaker::China::PhoneNumber::LANDLINE_PHONE_PREFIXES.sample
32
+ raise StandardError, "You're file is empty!" if prefix.length == 0
33
+ prefix
34
+ end
35
+
36
+ def generate_masks(mask_length = 1)
37
+ raise ArgumentError, "Pass a number greater than 1" if mask_length < 1
38
+ "#" * mask_length
39
+ end
40
+
41
+ def generate
42
+ if format == "mobile"
43
+ phone_prefix = mobile_prefix
44
+ phone_number_max_length = 11
45
+ prefix_length = phone_prefix.length
46
+ mask_length = phone_number_max_length - prefix_length
47
+ end
48
+
49
+ if format == "landline"
50
+ phone_prefix = landline_prefix
51
+ phone_number_max_length = eleven_digit_rule?(phone_prefix) ? 11 : 10
52
+ prefix_length = phone_prefix.length
53
+ mask_length = phone_number_max_length - prefix_length
54
+ end
55
+
56
+ masks = generate_masks(mask_length)
57
+
58
+ number = [
59
+ phone_prefix,
60
+ masks
61
+ ].join
62
+
63
+ DataMaker.numerify(number)
64
+ end
65
+
66
+ protected
67
+
68
+ attr_accessor :format
69
+
70
+ def eleven_digit_rule?(prefix)
71
+ [
72
+ 10,
73
+ 311,
74
+ 371,
75
+ 376,
76
+ 377,
77
+ 379,
78
+ 411,
79
+ 431,
80
+ 432,
81
+ 451,
82
+ 531,
83
+ 532,
84
+ 551,
85
+ 571,
86
+ 591,
87
+ 731,
88
+ 754,
89
+ 755,
90
+ 757,
91
+ 760,
92
+ 769,
93
+ 791,
94
+ 851,
95
+ 871
96
+ ].include?(prefix)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,328 @@
1
+ 10
2
+ 21
3
+ 22
4
+ 23
5
+ 24
6
+ 25
7
+ 26
8
+ 27
9
+ 28
10
+ 29
11
+ 20
12
+ 311
13
+ 312
14
+ 313
15
+ 314
16
+ 315
17
+ 316
18
+ 317
19
+ 318
20
+ 319
21
+ 310
22
+ 335
23
+ 351
24
+ 352
25
+ 353
26
+ 354
27
+ 355
28
+ 356
29
+ 357
30
+ 358
31
+ 359
32
+ 350
33
+ 349
34
+ 371
35
+ 372
36
+ 373
37
+ 374
38
+ 375
39
+ 376
40
+ 377
41
+ 379
42
+ 370
43
+ 391
44
+ 392
45
+ 393
46
+ 394
47
+ 395
48
+ 396
49
+ 398
50
+ 411
51
+ 412
52
+ 415
53
+ 416
54
+ 417
55
+ 418
56
+ 419
57
+ 421
58
+ 427
59
+ 429
60
+ 431
61
+ 432
62
+ 433
63
+ 434
64
+ 435
65
+ 436
66
+ 437
67
+ 438
68
+ 439
69
+ 440
70
+ 448
71
+ 451
72
+ 452
73
+ 453
74
+ 454
75
+ 455
76
+ 456
77
+ 457
78
+ 458
79
+ 459
80
+ 464
81
+ 467
82
+ 468
83
+ 469
84
+ 471
85
+ 472
86
+ 473
87
+ 474
88
+ 475
89
+ 476
90
+ 477
91
+ 478
92
+ 479
93
+ 470
94
+ 482
95
+ 483
96
+ 511
97
+ 512
98
+ 513
99
+ 514
100
+ 515
101
+ 516
102
+ 517
103
+ 518
104
+ 519
105
+ 510
106
+ 523
107
+ 527
108
+ 531
109
+ 532
110
+ 533
111
+ 534
112
+ 535
113
+ 536
114
+ 537
115
+ 538
116
+ 539
117
+ 530
118
+ 543
119
+ 546
120
+ 551
121
+ 552
122
+ 553
123
+ 554
124
+ 555
125
+ 556
126
+ 557
127
+ 558
128
+ 559
129
+ 550
130
+ 561
131
+ 562
132
+ 563
133
+ 564
134
+ 565
135
+ 566
136
+ 571
137
+ 572
138
+ 573
139
+ 574
140
+ 575
141
+ 576
142
+ 577
143
+ 578
144
+ 579
145
+ 570
146
+ 580
147
+ 591
148
+ 592
149
+ 593
150
+ 594
151
+ 595
152
+ 596
153
+ 597
154
+ 598
155
+ 599
156
+ 631
157
+ 632
158
+ 633
159
+ 634
160
+ 635
161
+ 638
162
+ 662
163
+ 663
164
+ 668
165
+ 660
166
+ 691
167
+ 692
168
+ 711
169
+ 712
170
+ 713
171
+ 714
172
+ 715
173
+ 716
174
+ 717
175
+ 718
176
+ 719
177
+ 710
178
+ 722
179
+ 724
180
+ 728
181
+ 731
182
+ 734
183
+ 735
184
+ 736
185
+ 737
186
+ 738
187
+ 739
188
+ 730
189
+ 743
190
+ 744
191
+ 745
192
+ 746
193
+ 751
194
+ 752
195
+ 753
196
+ 754
197
+ 755
198
+ 756
199
+ 757
200
+ 758
201
+ 759
202
+ 750
203
+ 760
204
+ 762
205
+ 763
206
+ 766
207
+ 768
208
+ 769
209
+ 771
210
+ 772
211
+ 773
212
+ 774
213
+ 775
214
+ 776
215
+ 777
216
+ 778
217
+ 779
218
+ 770
219
+ 791
220
+ 792
221
+ 793
222
+ 794
223
+ 795
224
+ 796
225
+ 797
226
+ 798
227
+ 799
228
+ 790
229
+ 701
230
+ 812
231
+ 813
232
+ 816
233
+ 817
234
+ 818
235
+ 825
236
+ 826
237
+ 827
238
+ 831
239
+ 832
240
+ 833
241
+ 834
242
+ 835
243
+ 836
244
+ 837
245
+ 838
246
+ 839
247
+ 830
248
+ 851
249
+ 854
250
+ 855
251
+ 856
252
+ 857
253
+ 858
254
+ 859
255
+ 871
256
+ 872
257
+ 873
258
+ 874
259
+ 875
260
+ 876
261
+ 877
262
+ 878
263
+ 879
264
+ 870
265
+ 881
266
+ 883
267
+ 886
268
+ 887
269
+ 888
270
+ 891
271
+ 892
272
+ 893
273
+ 894
274
+ 895
275
+ 896
276
+ 897
277
+ 898
278
+ 911
279
+ 912
280
+ 913
281
+ 914
282
+ 915
283
+ 916
284
+ 917
285
+ 919
286
+ 931
287
+ 932
288
+ 933
289
+ 934
290
+ 935
291
+ 936
292
+ 937
293
+ 938
294
+ 939
295
+ 930
296
+ 941
297
+ 943
298
+ 951
299
+ 952
300
+ 953
301
+ 954
302
+ 955
303
+ 971
304
+ 972
305
+ 973
306
+ 974
307
+ 975
308
+ 976
309
+ 977
310
+ 978
311
+ 979
312
+ 970
313
+ 991
314
+ 992
315
+ 993
316
+ 994
317
+ 995
318
+ 996
319
+ 997
320
+ 998
321
+ 999
322
+ 990
323
+ 901
324
+ 902
325
+ 903
326
+ 906
327
+ 908
328
+ 909