zfaker 0.0.2 → 0.0.3

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: 7b75b46837e0e43abbcf76ceb1381b3bc24fe337
4
- data.tar.gz: 96e07f09f43e3983b69d6ef392052ce1efbdd10e
3
+ metadata.gz: afd0dc4ea296cbb8624ab166382305fd1b99d985
4
+ data.tar.gz: f5d15cbe82cc86d8011a3f030f8b740ca24e7e75
5
5
  SHA512:
6
- metadata.gz: 5c56427660dc42456f4aa280c531f11a3b53ad0873e1f12a1ad9f9d8586a1c6fbb614596c91b2613bfea63cc158ec92253804b67743769e8ff2a4564492e2e8a
7
- data.tar.gz: b4262133db0c09e0dd550cba1584853238b95f0160c6af38f8b34de08116fd63e7cdc574370c83fc426f167e9d0f526bf646e7cf0623ffb66cb5036572135f43
6
+ metadata.gz: 5fbd45cfcf221d5fc40695bd77745044bf5fbf46ff5d465d9416c87e60542bb3d660468dac50de327e2aff58fa0e546b0b3cd3fd16ba7adad93b5233f98ae436
7
+ data.tar.gz: 433e6ca81f4a6aaea1f0669cae03fa6ac4867b0b5f1e8fbf2daab34dae50f085b326660314cfd7dd3cc84d5a15b86f732500f730c1fefc8c756d73555aacdbcb
@@ -3,8 +3,6 @@
3
3
  module ZFaker
4
4
  # Internet Module
5
5
  module Internet
6
- extend ModuleUtils
7
- extend self
8
6
 
9
7
  @emails = []
10
8
  @filler = ''
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module ZFaker
4
+ # Internet Module
5
+ module Name
6
+
7
+ @names = []
8
+
9
+ def name(first = nil, last = nil)
10
+ case [first.nil?, last.nil?]
11
+ when [true, true] then unique_sample(@names) { "#{first_name} #{last_name}" }
12
+ when [false, true] then unique_sample(@names) { "#{first} #{last_name}" }
13
+ when [true, false] then unique_sample(@names) { "#{first_name} #{last}" }
14
+ when [false, false] then unique_sample(@names) { "#{first} #{last}" }
15
+ else fail
16
+ end
17
+ end
18
+
19
+ def first_name
20
+ FIRST_NAMES.sample
21
+ end
22
+
23
+ def last_name
24
+ LAST_NAMES.sample
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Mackie
@@ -16,14 +16,11 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/zfaker.rb
20
- - lib/zfaker/data/internet/hosts
21
- - lib/zfaker/data/name/first_names
22
- - lib/zfaker/data/name/last_names
23
- - lib/zfaker/lib/internet.rb
24
- - lib/zfaker/lib/name.rb
25
- - lib/zfaker/utils/array_utils.rb
26
- - lib/zfaker/utils/module_utils.rb
19
+ - lib/custom/internet.rb
20
+ - lib/custom/name.rb
21
+ - lib/data/internet/hosts
22
+ - lib/data/name/first_names
23
+ - lib/data/name/last_names
27
24
  homepage: https://github.com/MacroMackie/zfaker
28
25
  licenses:
29
26
  - MIT
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module ZFaker
4
- # Name Module
5
- module Name
6
- extend ModuleUtils
7
- extend self
8
-
9
- @names = []
10
-
11
- def name(first = nil, last = nil)
12
- case [first.nil?, last.nil?]
13
- when [true, true] then unique_sample(@names) { "#{first_name} #{last_name}" }
14
- when [false, true] then unique_sample(@names) { "#{first} #{last_name}" }
15
- when [true, false] then unique_sample(@names) { "#{first_name} #{last}" }
16
- when [false, false] then unique_sample(@names) { "#{first} #{last}" }
17
- else fail
18
- end
19
- end
20
-
21
- def first_name
22
- FIRST_NAMES.sample
23
- end
24
-
25
- def last_name
26
- LAST_NAMES.sample
27
- end
28
- end
29
- end
@@ -1,48 +0,0 @@
1
- module ZFaker
2
- # Module ArrayUtils
3
- module ArrayUtils
4
- def self.const_array(argument)
5
- array = argument.is_a?(Array) ? argument : argument.to_a
6
- array.extend ArrayUtils
7
- freeze_all(array)
8
- end
9
-
10
- def self.random_pick(array, n)
11
- warn '[ArrayUtils.random_pick] is deprecated. Please use the Array#sample method'
12
- array.sample(n)
13
- end
14
-
15
- def self.rand(array)
16
- warn '[ArrayUtils.rand] is deprecated. Please use the Array#sample method'
17
- array.sample
18
- end
19
-
20
- def self.freeze_all(array)
21
- array.each(&:freeze)
22
- array.freeze
23
- array
24
- end
25
-
26
- def self.shuffle(array)
27
- array.sort_by { Kernel.rand }
28
- end
29
-
30
- def random_pick(n)
31
- warn '[ArrayUtils#random_pick] is deprecated. Please use the Array#sample method'
32
- sample(n)
33
- end
34
-
35
- def rand
36
- warn '[ArrayUtils#rand] is deprecated. Please use the Array#sample method'
37
- sample
38
- end
39
-
40
- def freeze_all
41
- ArrayUtils.freeze_all(self)
42
- end
43
-
44
- def shuffle
45
- ArrayUtils.shuffle(self)
46
- end
47
- end
48
- end
@@ -1,70 +0,0 @@
1
- require_relative './array_utils'
2
-
3
- module ZFaker
4
- # Module ModuleUtils
5
- module ModuleUtils
6
- def k(arg) ZFaker::ArrayUtils.const_array(arg)
7
- end
8
-
9
- def const_missing(const_name)
10
- if const_name =~ /[a-z]/ # Not a constant, probably a class/module name.
11
- super const_name
12
- else
13
- mod_name = ancestors.first.to_s.split('::').last
14
- data_path = "#{ZFaker::BASE_LIB_PATH}/zfaker/data/#{underscore(mod_name)}/#{underscore(const_name.to_s)}"
15
- reader = k File.read(data_path).split("\n")
16
- arrout = []
17
- reader.each do |x|
18
- cut = x.split(' ')
19
- if cut.size > 1 && cut[0].integer?
20
- weight = cut[0].to_i
21
- element = cut[1..-1].join(' ')
22
- element = '' if element == '<blank>'
23
- else
24
- weight = 1
25
- element = cut[0..-1].join(' ')
26
- end
27
- weight.times { arrout.push(element) }
28
- end
29
- const_set const_name, arrout
30
- arrout
31
- end
32
- end
33
-
34
- def underscore(string)
35
- string.gsub(/::/, '/')
36
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
37
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
38
- .tr('-', '_')
39
- .downcase
40
- end
41
-
42
- def unique_sample(arr)
43
- sample = ''
44
- collisions = 0
45
- loop do
46
- sample = yield
47
- break unless arr.include? sample
48
- collisions += 1
49
- fail 'Too Many Collisions: ' + collisions.to_s if collisions > (arr.size + 50) * 10
50
- end
51
- arr.push sample
52
- sample
53
- end
54
- end
55
- end
56
-
57
- # String Class
58
- class String
59
- def integer?
60
- [ # In descending order of likeliness:
61
- /^[-+]?[1-9]([0-9]*)?$/, # decimal
62
- /^0[0-7]+$/, # octal
63
- /^0x[0-9A-Fa-f]+$/, # hexadecimal
64
- /^0b[01]+$/ # binary
65
- ].each do |match_pattern|
66
- return true if self =~ match_pattern
67
- end
68
- false
69
- end
70
- end
data/lib/zfaker.rb DELETED
@@ -1,34 +0,0 @@
1
- # ZFaker Module
2
- module ZFaker
3
- require_relative 'zfaker/utils/array_utils'
4
- require_relative 'zfaker/utils/module_utils'
5
-
6
- extend ModuleUtils
7
-
8
- BASE_LIB_PATH = File.expand_path('..', __FILE__)
9
-
10
- LETTERS = [*'a'..'z']
11
-
12
- HEX = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F)
13
-
14
- def self.hexify(*masks)
15
- masks.flatten.sample.gsub(/#/) { HEX.sample }
16
- end
17
-
18
- def self.numerify(*masks)
19
- masks.flatten.sample.gsub(/#/) { rand(10).to_s }
20
- end
21
-
22
- def self.letterify(*masks)
23
- masks.flatten.sample.gsub(/\?/) { LETTERS.sample }
24
- end
25
-
26
- def self.bothify(masks)
27
- letterify(numerify(masks))
28
- end
29
-
30
- # Load all constants.
31
- Dir["#{BASE_LIB_PATH}/**/zfaker/lib/*.rb"].sort.each do |f|
32
- require_relative "zfaker/lib/#{File.basename(f, '.rb')}"
33
- end
34
- end
File without changes
File without changes
File without changes