bsielski_value_generator 1.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 +7 -0
- data/.gitignore +27 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +295 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bsielski_value_generator.gemspec +37 -0
- data/lib/bsielski_v_gen.rb +5 -0
- data/lib/bsielski_v_gen/array_gen.rb +20 -0
- data/lib/bsielski_v_gen/float_gen.rb +15 -0
- data/lib/bsielski_v_gen/hash_gen.rb +35 -0
- data/lib/bsielski_v_gen/int_gen.rb +13 -0
- data/lib/bsielski_v_gen/keyword_gen.rb +15 -0
- data/lib/bsielski_v_gen/letter_gen.rb +14 -0
- data/lib/bsielski_v_gen/lower_letter_gen.rb +12 -0
- data/lib/bsielski_v_gen/old_array_gen.rb +41 -0
- data/lib/bsielski_v_gen/old_hash_gen.rb +47 -0
- data/lib/bsielski_v_gen/typical_letter_gen.rb +21 -0
- data/lib/bsielski_v_gen/upper_letter_gen.rb +12 -0
- data/lib/bsielski_v_gen/var_word_gen.rb +30 -0
- data/lib/bsielski_v_gen/version.rb +3 -0
- data/lib/bsielski_v_gen/whatever_gen.rb +13 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af7e24f785b22523889f163bf9a0cbb5cd2db7971f7d29647105168406733259
|
4
|
+
data.tar.gz: 9df15e57cc74efcba5282a5b2404116ff002a21b0a7c5469c16a384f9d926518
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa65f2cac221d6699a6ce7b8906e765e13c798d7ccb8e27591976c44935997ac950e7a3d0bfd7ec8212762a3d9a6d108e50a66c3edd9079674822b312fef407c
|
7
|
+
data.tar.gz: 4e1417cd7cb93d0827992287851b598e188b76dbaec61f70d57022fe14edb3ce4baac59e75d55373545a75fcec8dcb8b80e3fe69dade23b4056c7de88269b15f
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
12
|
+
|
13
|
+
*.gem
|
14
|
+
Gemfile.lock
|
15
|
+
|
16
|
+
# Ignore vendor/bundle
|
17
|
+
/vendor/bundle
|
18
|
+
|
19
|
+
# Ignore Emacs garbage
|
20
|
+
*~
|
21
|
+
.*~
|
22
|
+
\#*.*#
|
23
|
+
.#*.*
|
24
|
+
|
25
|
+
# Ignore design docs
|
26
|
+
*.org
|
27
|
+
*.org#
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Bartłomiej Sielski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
# bsielski Value Generator
|
2
|
+
|
3
|
+
This gem can:
|
4
|
+
- create random int, float, string, and symbols
|
5
|
+
- create a random value of random type
|
6
|
+
- create an array of random values
|
7
|
+
- create a hash of random key and values
|
8
|
+
|
9
|
+
## Why to use it?
|
10
|
+
|
11
|
+
Who knows. I have made it when I was creating a code with functional style and was working mainly with hashes as a data containers and I wanted some configurable generator of random hashes for my unit tests.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'bsielski_value_generator'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install bsielski_value_generator
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Reqiure proper class.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require "v_gen/int_gen"
|
35
|
+
```
|
36
|
+
|
37
|
+
Use it.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
random_int = VGen::IntGen.new.call
|
41
|
+
|
42
|
+
# or
|
43
|
+
|
44
|
+
int_gen = VGen::IntGen.new
|
45
|
+
random_int = int_gen.call
|
46
|
+
```
|
47
|
+
|
48
|
+
All generators have just one public method: `#call`.
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
## API
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
### VGen::IntGen
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require "v_gen/int_gen"
|
60
|
+
```
|
61
|
+
|
62
|
+
#### Class Public Methods
|
63
|
+
|
64
|
+
##### `new(range=(0..10)) → new_generator`
|
65
|
+
|
66
|
+
*range* is the range from which the number is randomly generated.
|
67
|
+
|
68
|
+
#### Public Instance Methods
|
69
|
+
|
70
|
+
##### `call → new_int`
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
### VGen::FloatGen
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
require "v_gen/float_gen"
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Class Public Methods
|
81
|
+
|
82
|
+
##### `new(range=(-10..10)) → new_generator`
|
83
|
+
|
84
|
+
See VGen::IntGen.new for details about *range* argument.
|
85
|
+
|
86
|
+
#### Public Instance Methods
|
87
|
+
|
88
|
+
##### `call → new_float`
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
### VGen::LetterGen
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require "v_gen/letter_gen"
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Class Public Methods
|
99
|
+
|
100
|
+
##### `new(only: (("A".."Z").to_a + ("a".."z").to_a), except: []) → new_generator`
|
101
|
+
|
102
|
+
*only* an array (or range) of objects from which one randomly chosen is returned.
|
103
|
+
|
104
|
+
*except* an array (or range) that is substracted from *only* array (range).
|
105
|
+
|
106
|
+
#### Public Instance Methods
|
107
|
+
|
108
|
+
##### `call → new_object`
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
### VGen::LowerLetterGen
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
require "v_gen/lower_letter_gen"
|
116
|
+
```
|
117
|
+
|
118
|
+
#### Class Public Methods
|
119
|
+
|
120
|
+
##### `new(only: ("A".."Z"), except: []) → new_generator`
|
121
|
+
|
122
|
+
See VGen::LetterGen.new for details about *only* and *except* arguments.
|
123
|
+
|
124
|
+
The object in *only* and *except* arrays or ranges must respond to `#downcase` method.
|
125
|
+
|
126
|
+
#### Public Instance Methods
|
127
|
+
|
128
|
+
##### `call → new_lowercased_object`
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
#### Example
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
lower_letter_gen = VGen::LowerLetterGen.new(only: ("A".."Z"))
|
136
|
+
lower_letter_gen.call # => "j"
|
137
|
+
lower_letter_gen.call # => "e"
|
138
|
+
```
|
139
|
+
|
140
|
+
### VGen::UpperLetterGen
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
require "v_gen/upper_letter_gen"
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Class Public Methods
|
147
|
+
|
148
|
+
##### `new(only: ("A".."Z"), except: []) → new_generator`
|
149
|
+
|
150
|
+
See VGen::LetterGen.new for details about *only* and *except* arguments.
|
151
|
+
|
152
|
+
The object in *only* and *except* arrays or ranges must respond to `#upcase` method.
|
153
|
+
|
154
|
+
#### Public Instance Methods
|
155
|
+
|
156
|
+
##### `call → new_uppercased_object`
|
157
|
+
|
158
|
+
#### Example
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
upper_letter_gen = VGen::UpperLetterGen.new(only: ("A".."Z"))
|
162
|
+
upper_letter_gen.call # => "I"
|
163
|
+
upper_letter_gen.call # => "D"
|
164
|
+
```
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
### VGen::TypicalLetterGen
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
require "v_gen/typical_letter_gen"
|
172
|
+
```
|
173
|
+
|
174
|
+
#### Class Public Methods
|
175
|
+
|
176
|
+
##### `new → new_generator`
|
177
|
+
|
178
|
+
#### Public Instance Methods
|
179
|
+
|
180
|
+
##### `call → new_letter`
|
181
|
+
|
182
|
+
It returns a random lowercased letter with taking into account the frequency of occurrence in English language.
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
### VGen::VarWordGen
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
require "v_gen/var_word_gen"
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Class Public Methods
|
193
|
+
|
194
|
+
##### `new(letter_gen: TypicalLetterGen.new, lenght: (4..9), except: []) → new_generator`
|
195
|
+
|
196
|
+
*letter_gen* is a generator used to creating a letters for words.
|
197
|
+
|
198
|
+
*length* possible word length as a range.
|
199
|
+
|
200
|
+
*except* words forbidden to generate.
|
201
|
+
|
202
|
+
#### Public Instance Methods
|
203
|
+
|
204
|
+
##### `call(lenght: (4..9), except: []) → new_random_word`
|
205
|
+
|
206
|
+
It returns a random lowercased word sometimes with underscore in the middle.
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
### VGen::KeywordGen
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
require "v_gen/keyword_gen"
|
214
|
+
```
|
215
|
+
|
216
|
+
#### Class Public Methods
|
217
|
+
|
218
|
+
##### `new(word_gen: VarWordGen.new) → new_generator`
|
219
|
+
|
220
|
+
*word_gen* is a generator used to creating a word that will be converted to a symbol.
|
221
|
+
|
222
|
+
#### Public Instance Methods
|
223
|
+
|
224
|
+
##### `call → new_random_word`
|
225
|
+
|
226
|
+
It returns a random lowercased word sometimes with underscore in the middle.
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
### VGen::ArrayGen
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
require "v_gen/array_gen"
|
234
|
+
```
|
235
|
+
|
236
|
+
#### Class Public Methods
|
237
|
+
|
238
|
+
##### `new(min: 4, max: 8, gens: [proc {Random.new.rand}]) → new_generator`
|
239
|
+
|
240
|
+
*min* is a minimum size of a generated arrays.
|
241
|
+
|
242
|
+
*max* is a maximum size of a generated arrays.
|
243
|
+
|
244
|
+
*gens* are generators used randomly to generate values.
|
245
|
+
|
246
|
+
#### Public Instance Methods
|
247
|
+
|
248
|
+
##### `call → new_random_word`
|
249
|
+
|
250
|
+
It returns an array of random values.
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
### VGen::HashGen
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
require "v_gen/hash_gen"
|
258
|
+
```
|
259
|
+
|
260
|
+
#### Class Public Methods
|
261
|
+
|
262
|
+
##### `new(min: 4, max: 8, key_gens: [proc {Random.new.rand(0..100)}], value_gens: [proc {Random.new.rand}]) → new_generator`
|
263
|
+
|
264
|
+
*min* is a minimum size of a generated arrays.
|
265
|
+
|
266
|
+
*max* is a maximum size of a generated arrays.
|
267
|
+
|
268
|
+
*key_gens* are generators used randomly to generate keys.
|
269
|
+
|
270
|
+
*value_gens* are generators used randomly to generate values.
|
271
|
+
|
272
|
+
#### Public Instance Methods
|
273
|
+
|
274
|
+
##### `call → new_random_word`
|
275
|
+
|
276
|
+
It returns a hash of random keys and values.
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
## To do features
|
284
|
+
|
285
|
+
- Better API
|
286
|
+
- Some easy to use generators with default parameters
|
287
|
+
|
288
|
+
## To do features
|
289
|
+
|
290
|
+
- Better API
|
291
|
+
- Some easy to use generators with default parameters
|
292
|
+
|
293
|
+
## License
|
294
|
+
|
295
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bsielski_value_generator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "bsielski_v_gen/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "bsielski_value_generator"
|
9
|
+
spec.version = VGen::VERSION
|
10
|
+
spec.authors = ["Bartłomiej Sielski"]
|
11
|
+
spec.email = ["b.sielski.webdev@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Generators for random values (ints, strings, arrays, hashes etc.)}
|
14
|
+
# spec.description = %q{Write a longer description or delete this line.}
|
15
|
+
spec.homepage = "https://github.com/bsielski/bsielski_value_generator"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
# else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
# "public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VGen
|
2
|
+
class ArrayGen
|
3
|
+
def initialize(
|
4
|
+
min: 4,
|
5
|
+
max: 8,
|
6
|
+
gens: [ proc {Random.new.rand} ]
|
7
|
+
)
|
8
|
+
@gens = gens
|
9
|
+
@min = min
|
10
|
+
@max = max
|
11
|
+
end
|
12
|
+
|
13
|
+
def call()
|
14
|
+
arr = Array.new(Random.new.rand(@min..@max)) {
|
15
|
+
@gens.sample
|
16
|
+
}
|
17
|
+
arr.map(&:call)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module VGen
|
2
|
+
class HashGen
|
3
|
+
def initialize(
|
4
|
+
min: 4,
|
5
|
+
max: 8,
|
6
|
+
key_gens: [ proc {Random.new.rand(0..100)} ],
|
7
|
+
value_gens: [ proc {Random.new.rand} ]
|
8
|
+
)
|
9
|
+
@key_gens = key_gens
|
10
|
+
@value_gens = value_gens
|
11
|
+
@min = min
|
12
|
+
@max = max
|
13
|
+
end
|
14
|
+
|
15
|
+
def call()
|
16
|
+
length = Random.new.rand(@min..@max)
|
17
|
+
hash = Hash[
|
18
|
+
Array.new(length) do
|
19
|
+
[
|
20
|
+
@key_gens.sample.call,
|
21
|
+
@value_gens.sample.call
|
22
|
+
]
|
23
|
+
end
|
24
|
+
]
|
25
|
+
while hash.size < length do
|
26
|
+
hash = hash.merge(
|
27
|
+
{
|
28
|
+
@key_gens.sample.call => @value_gens.sample.call
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "./int_gen"
|
2
|
+
require_relative "./float_gen"
|
3
|
+
require_relative "./var_word_gen"
|
4
|
+
require_relative "./hash_gen"
|
5
|
+
require_relative "./keyword_gen"
|
6
|
+
|
7
|
+
module VGen
|
8
|
+
class ArrayGen
|
9
|
+
def initialize(max_depth: 3)
|
10
|
+
@max_depth = max_depth
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(
|
14
|
+
only: [
|
15
|
+
IntGen.new,
|
16
|
+
FloatGen.new,
|
17
|
+
VarWordGen.new,
|
18
|
+
self.class.new,
|
19
|
+
KeywordGen.new
|
20
|
+
],
|
21
|
+
except: [],
|
22
|
+
min: 4,
|
23
|
+
max: 8)
|
24
|
+
gens = [] + only
|
25
|
+
gens.delete_if {|e| except.include? e.class}
|
26
|
+
if @max_depth == 0
|
27
|
+
gens.delete_if {|e| e.class == self.class}
|
28
|
+
end
|
29
|
+
if @max_depth > 0
|
30
|
+
gens = gens.map do |e|
|
31
|
+
next e unless e.class == self.class
|
32
|
+
if e.class == self.class
|
33
|
+
next self.class.new(max_depth: @max_depth - 1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
arr = Array.new(Random.new.rand(min..max)) { gens.sample }
|
38
|
+
arr.map(&:call)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "./int_gen"
|
2
|
+
require_relative "./float_gen"
|
3
|
+
require_relative "./var_word_gen"
|
4
|
+
require_relative "./array_gen"
|
5
|
+
require_relative "./keyword_gen"
|
6
|
+
|
7
|
+
module VGen
|
8
|
+
class HashGen
|
9
|
+
def initialize(max_depth: 3)
|
10
|
+
@max_depth = max_depth
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(
|
14
|
+
only: [
|
15
|
+
IntGen.new,
|
16
|
+
FloatGen.new,
|
17
|
+
VarWordGen.new,
|
18
|
+
ArrayGen.new,
|
19
|
+
self.class.new,
|
20
|
+
KeywordGen.new
|
21
|
+
],
|
22
|
+
except: [],
|
23
|
+
min: 4,
|
24
|
+
max: 8
|
25
|
+
)
|
26
|
+
val_gens = [] + only
|
27
|
+
val_gens.delete_if {|e| except.include? e.class}
|
28
|
+
if @max_depth == 0
|
29
|
+
val_gens.delete_if {|e| e.class == ArrayGen}
|
30
|
+
val_gens.delete_if {|e| e.class == self.class}
|
31
|
+
end
|
32
|
+
if @max_depth > 0
|
33
|
+
val_gens.map do |e|
|
34
|
+
next e unless (e.class == ArrayGen || e.class == self.class)
|
35
|
+
if e.class == ArrayGen
|
36
|
+
next ArrayGen.new(max_depth: @max_depth - 1)
|
37
|
+
end
|
38
|
+
if e.class == self.class
|
39
|
+
next self.class.new(max_depth: @max_depth - 1)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
key_gens = [IntGen.new, VarWordGen.new, KeywordGen.new]
|
44
|
+
hash = Hash[Array.new(Random.new.rand(min..max)) { [key_gens.sample.call, val_gens.sample.call] }]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VGen
|
2
|
+
class TypicalLetterGen
|
3
|
+
def call
|
4
|
+
table = {
|
5
|
+
0...816=>"a", 816...965=>"b", 965...1243=>"c",
|
6
|
+
1243...1668=>"d", 1668...2938=>"e", 2938...3160=>"f",
|
7
|
+
3160...3361=>"g", 3361...3970=>"h", 3970...4666=>"i",
|
8
|
+
4666...4681=>"j", 4681...4758=>"k", 4758...5160=>"l",
|
9
|
+
5160...5400=>"m", 5400...6074=>"n", 6074...6824=>"o",
|
10
|
+
6824...7016=>"p", 7016...7025=>"q", 7025...7623=>"r",
|
11
|
+
7623...8255=>"s", 8255...9160=>"t", 9160...9435=>"u",
|
12
|
+
9435...9532=>"v", 9532...9768=>"w", 9768...9783=>"x",
|
13
|
+
9783...9980=>"y", 9980...9987=>"z"
|
14
|
+
}
|
15
|
+
i = Random.new.rand(0...9987)
|
16
|
+
table.each do |range, letter|
|
17
|
+
return letter if range.include? i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "./typical_letter_gen"
|
2
|
+
|
3
|
+
module VGen
|
4
|
+
class VarWordGen
|
5
|
+
def initialize(
|
6
|
+
letter_gen: TypicalLetterGen.new,
|
7
|
+
length: (4..9),
|
8
|
+
except: []
|
9
|
+
)
|
10
|
+
@length = length
|
11
|
+
@letter_gen = letter_gen
|
12
|
+
@except = except
|
13
|
+
end
|
14
|
+
|
15
|
+
def call()
|
16
|
+
loop do
|
17
|
+
word = Array.new(
|
18
|
+
Random.new.rand(@length),
|
19
|
+
@letter_gen
|
20
|
+
).map(&:call).join
|
21
|
+
if word.size > 2
|
22
|
+
if Random.new.rand(1..100) < 15
|
23
|
+
word[Random.new.rand(1..word.size - 2)] = "_"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
return word unless @except.include? word
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bsielski_value_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bartłomiej Sielski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-24 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- b.sielski.webdev@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- bsielski_value_generator.gemspec
|
72
|
+
- lib/bsielski_v_gen.rb
|
73
|
+
- lib/bsielski_v_gen/array_gen.rb
|
74
|
+
- lib/bsielski_v_gen/float_gen.rb
|
75
|
+
- lib/bsielski_v_gen/hash_gen.rb
|
76
|
+
- lib/bsielski_v_gen/int_gen.rb
|
77
|
+
- lib/bsielski_v_gen/keyword_gen.rb
|
78
|
+
- lib/bsielski_v_gen/letter_gen.rb
|
79
|
+
- lib/bsielski_v_gen/lower_letter_gen.rb
|
80
|
+
- lib/bsielski_v_gen/old_array_gen.rb
|
81
|
+
- lib/bsielski_v_gen/old_hash_gen.rb
|
82
|
+
- lib/bsielski_v_gen/typical_letter_gen.rb
|
83
|
+
- lib/bsielski_v_gen/upper_letter_gen.rb
|
84
|
+
- lib/bsielski_v_gen/var_word_gen.rb
|
85
|
+
- lib/bsielski_v_gen/version.rb
|
86
|
+
- lib/bsielski_v_gen/whatever_gen.rb
|
87
|
+
homepage: https://github.com/bsielski/bsielski_value_generator
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Generators for random values (ints, strings, arrays, hashes etc.)
|
111
|
+
test_files: []
|