randomperson 0.0.19 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +2 -0
- data/Manifest +22 -2
- data/README.markdown +475 -0
- data/lib/randomperson/Loader.rb +62 -0
- data/lib/randomperson/Names/AmericanFemaleFirst.rb +10 -8
- data/lib/randomperson/Names/AmericanLast.rb +13 -10
- data/lib/randomperson/Names/AmericanMaleFirst.rb +11 -8
- data/lib/randomperson/Names/AmericanPrefix.rb +16 -18
- data/lib/randomperson/Names/AmericanSuffix.rb +26 -16
- data/lib/randomperson/Names/AncientGreekFemaleFirst.rb +12 -8
- data/lib/randomperson/Names/AncientGreekLast.rb +11 -8
- data/lib/randomperson/Names/AncientGreekMaleFirst.rb +11 -8
- data/lib/randomperson/Names/AnyLast.rb +11 -9
- data/lib/randomperson/Names/BasqueFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/BasqueLast.rb +9 -8
- data/lib/randomperson/Names/BasqueMaleFirst.rb +10 -9
- data/lib/randomperson/Names/BritishPrefix.rb +10 -16
- data/lib/randomperson/Names/BritishSuffix.rb +21 -16
- data/lib/randomperson/Names/EnglishFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/EnglishLast.rb +12 -11
- data/lib/randomperson/Names/EnglishMaleFirst.rb +10 -9
- data/lib/randomperson/Names/EnglishPrefix.rb +11 -15
- data/lib/randomperson/Names/FinnishFemaleFirst.rb +10 -8
- data/lib/randomperson/Names/FinnishLast.rb +9 -8
- data/lib/randomperson/Names/FinnishMaleFirst.rb +10 -9
- data/lib/randomperson/Names/FinnishPrefix.rb +16 -18
- data/lib/randomperson/Names/FrenchFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/FrenchLast.rb +12 -11
- data/lib/randomperson/Names/FrenchMaleFirst.rb +11 -10
- data/lib/randomperson/Names/GermanFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/GermanLast.rb +9 -8
- data/lib/randomperson/Names/GermanMaleFirst.rb +10 -9
- data/lib/randomperson/Names/ScottishFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/ScottishLast.rb +11 -10
- data/lib/randomperson/Names/ScottishMaleFirst.rb +13 -12
- data/lib/randomperson/Names/ScottishPrefix.rb +10 -16
- data/lib/randomperson/Names/SpanishFemaleFirst.rb +11 -10
- data/lib/randomperson/Names/SpanishLast.rb +15 -12
- data/lib/randomperson/Names/SpanishMaleFirst.rb +12 -11
- data/lib/randomperson/Names/SpanishPrefix.rb +17 -19
- data/lib/randomperson/Names/SwedishFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/SwedishLast.rb +10 -9
- data/lib/randomperson/Names/SwedishMaleFirst.rb +15 -14
- data/lib/randomperson/Names/ThaiFemaleFirst.rb +9 -8
- data/lib/randomperson/Names/ThaiFirst.rb +9 -8
- data/lib/randomperson/Names/ThaiLast.rb +9 -8
- data/lib/randomperson/Names/ThaiMaleFirst.rb +9 -8
- data/lib/randomperson/Names/ThaiRomanisedFemaleFirst.rb +10 -9
- data/lib/randomperson/Names/ThaiRomanisedLast.rb +11 -10
- data/lib/randomperson/Names/ThaiRomanisedMaleFirst.rb +10 -9
- data/lib/randomperson/Names/WelshFemaleFirst.rb +9 -8
- data/lib/randomperson/Names/WelshLast.rb +11 -10
- data/lib/randomperson/Names/WelshMaleFirst.rb +9 -8
- data/lib/randomperson/Names/WelshPrefix.rb +10 -16
- data/lib/randomperson/Outputter.rb +53 -0
- data/lib/randomperson/demographic.rb +75 -0
- data/lib/randomperson/ext/Array.rb +6 -2
- data/lib/randomperson/generator.rb +54 -77
- data/lib/randomperson/name.rb +18 -13
- data/lib/randomperson/person.rb +2 -0
- data/lib/randomperson/version.rb +1 -1
- data/lib/randomperson.rb +126 -1
- data/spec/AmericanSuffix_spec.rb +37 -0
- data/spec/AnyLast_spec.rb +25 -0
- data/spec/Last_and_First_Names_spec.rb +113 -0
- data/spec/array_spec.rb +49 -0
- data/spec/demographic_spec.rb +15 -0
- data/spec/generator_spec.rb +1 -4
- data/spec/name_spec.rb +3 -2
- data/spec/randomperson_spec.rb +321 -0
- data/spec/rspec_helper.rb +22 -0
- data/spec/support/helpers.rb +13 -0
- data/spec/support/matchers/all.rb +14 -0
- data/spec/support/matchers/be_in.rb +9 -0
- data/spec/support/shared_examples/names.rb +59 -0
- data/test/benchmarks/concat_or_add.rb +30 -0
- data/test/benchmarks/my_assoc_or_select.rb +60 -0
- data.tar.gz.sig +0 -0
- metadata +35 -7
- metadata.gz.sig +2 -3
- data/README +0 -324
- data/lib/randomperson/choice.rb +0 -113
- data/spec/choice_spec.rb +0 -13
@@ -0,0 +1,321 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative "./rspec_helper.rb"
|
4
|
+
require_relative "../lib/randomperson.rb"
|
5
|
+
|
6
|
+
shared_examples "a Person" do
|
7
|
+
it { subject.first.should_not be_nil }
|
8
|
+
it { subject.first.should be_a_kind_of String }
|
9
|
+
it { subject.last.should_not be_nil }
|
10
|
+
it { subject.last.should be_a_kind_of String }
|
11
|
+
it { subject.prefix.should_not be_nil }
|
12
|
+
it { subject.prefix.should be_a_kind_of String }
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples "there is more than one demographic" do
|
16
|
+
context "Given a new demographic" do
|
17
|
+
before(:all) { r.demographic("America").add_American }
|
18
|
+
context "but not changing to it" do
|
19
|
+
let(:last_run) { r.person }
|
20
|
+
subject { last_run }
|
21
|
+
it { should equal first_run }
|
22
|
+
context "changing to the new demographic" do
|
23
|
+
let(:new_demo_person) { r.person "America" }
|
24
|
+
subject { new_demo_person }
|
25
|
+
it { should_not equal last_run }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples "getting the last person" do
|
32
|
+
context "on first run" do
|
33
|
+
subject{ first_run }
|
34
|
+
it_behaves_like "a Person"
|
35
|
+
context "on next run" do
|
36
|
+
context "Given no demographic" do
|
37
|
+
subject { r.person }
|
38
|
+
it { should equal first_run }
|
39
|
+
end
|
40
|
+
context "Given the same demographic" do
|
41
|
+
subject{ r.person "Spain" }
|
42
|
+
it { should equal first_run }
|
43
|
+
it_behaves_like "there is more than one demographic"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
shared_examples "clear or reset" do
|
50
|
+
let(:r) { RandomPerson() }
|
51
|
+
before(:all) {
|
52
|
+
r.demographic("Spain").add_Spanish
|
53
|
+
r.demographic("Finland").add_Finnish
|
54
|
+
r.generate "Spain"
|
55
|
+
r.generate
|
56
|
+
r.generate "Finland"
|
57
|
+
r.generate
|
58
|
+
r.generate "Spain"
|
59
|
+
}
|
60
|
+
subject { r.clear }
|
61
|
+
it { should be_nil }
|
62
|
+
specify { r.should_not be_nil }
|
63
|
+
specify { r.should be_a_kind_of RandomPerson::Facade }
|
64
|
+
specify { r.generators.should be_empty }
|
65
|
+
specify { r.demographics.should be_empty }
|
66
|
+
specify { expect { r.person }.to raise_error }
|
67
|
+
specify { expect { r.generate }.to raise_error }
|
68
|
+
specify { expect { r.gen_new }.to raise_error }
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
describe RandomPerson do
|
73
|
+
|
74
|
+
describe :person do
|
75
|
+
let(:r) { RandomPerson() }
|
76
|
+
context "Given a demographic" do
|
77
|
+
context "With a name" do
|
78
|
+
context "and one demographic specified" do
|
79
|
+
before(:all) {
|
80
|
+
r.demographic("Spain").add_Spanish
|
81
|
+
}
|
82
|
+
let(:first_run) { r.person "Spain" }
|
83
|
+
subject{ first_run }
|
84
|
+
it_behaves_like "a Person"
|
85
|
+
context "on next run" do
|
86
|
+
context "Given no demographic" do
|
87
|
+
subject { r.person }
|
88
|
+
it { should equal first_run }
|
89
|
+
context "and then given the same demographic explicitly" do
|
90
|
+
subject{ r.person "Spain" }
|
91
|
+
it { should equal first_run }
|
92
|
+
context "and then given a demo name that doesn't exist" do
|
93
|
+
subject{ r.person "Spurious" }
|
94
|
+
it { should be_nil }
|
95
|
+
context "and then given no demo name" do
|
96
|
+
subject{ r.person }
|
97
|
+
it { should equal first_run }
|
98
|
+
end
|
99
|
+
context "and then given the last good demographic explicitly" do
|
100
|
+
subject{ r.person "Spain" }
|
101
|
+
it { should equal first_run }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "and no demographic specified" do
|
110
|
+
before(:all) {
|
111
|
+
r.demographic("Spain").add_Spanish
|
112
|
+
}
|
113
|
+
let(:first_run) { r.person }
|
114
|
+
it_behaves_like "getting the last person"
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
context "Without a name" do
|
120
|
+
context "and with a demographic specified" do
|
121
|
+
before(:all) {
|
122
|
+
r.clear
|
123
|
+
r.demographic.add_Spanish
|
124
|
+
}
|
125
|
+
subject { r.person "Spain" }
|
126
|
+
it { should be_nil }
|
127
|
+
end
|
128
|
+
|
129
|
+
context "and no demographic specified" do
|
130
|
+
before(:all) {
|
131
|
+
r.demographic.add_Spanish
|
132
|
+
}
|
133
|
+
let(:first_run) { r.person }
|
134
|
+
subject { r.person }
|
135
|
+
it { should equal first_run }
|
136
|
+
context "on repeated runs" do
|
137
|
+
before(:all) {
|
138
|
+
r.clear
|
139
|
+
r.demographic.add_Spanish
|
140
|
+
r.generate
|
141
|
+
r.generate
|
142
|
+
}
|
143
|
+
let(:last) { r.person }
|
144
|
+
subject { r.person }
|
145
|
+
it { should equal last }
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
context "With no demographic" do
|
152
|
+
context "Already loaded" do
|
153
|
+
subject { r.person }
|
154
|
+
specify { expect { subject }.to raise_error }
|
155
|
+
context "and given a demo name" do
|
156
|
+
subject { r.person "Not loaded" }
|
157
|
+
specify { expect { subject }.to raise_error }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
context "Because they've been cleared" do
|
161
|
+
subject { r.person }
|
162
|
+
specify { expect { subject }.to raise_error }
|
163
|
+
context "and given a demo name" do
|
164
|
+
subject { r.person "Been cleared" }
|
165
|
+
specify { expect { subject }.to raise_error }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end # :person
|
170
|
+
|
171
|
+
|
172
|
+
describe :generators do
|
173
|
+
let(:r) { RandomPerson() }
|
174
|
+
before(:all) {
|
175
|
+
r.demographic("Spain").add_Spanish
|
176
|
+
r.demographic("Finland").add_Finnish
|
177
|
+
}
|
178
|
+
context "Before first run" do
|
179
|
+
subject { r.generators }
|
180
|
+
it { should be_empty }
|
181
|
+
end
|
182
|
+
context "First run" do
|
183
|
+
before {
|
184
|
+
r.generate "Spain"
|
185
|
+
r.generate
|
186
|
+
r.generate "Finland"
|
187
|
+
r.generate
|
188
|
+
r.generate "Spain"
|
189
|
+
}
|
190
|
+
subject { r.generators }
|
191
|
+
it { should_not be_empty }
|
192
|
+
specify { subject.keys.should include("Spain", "Finland") }
|
193
|
+
end
|
194
|
+
end # generators
|
195
|
+
|
196
|
+
describe :clear do
|
197
|
+
it_behaves_like "clear or reset"
|
198
|
+
end
|
199
|
+
|
200
|
+
describe :reset do
|
201
|
+
it_behaves_like "clear or reset"
|
202
|
+
end
|
203
|
+
|
204
|
+
describe :generate do
|
205
|
+
let(:r) { RandomPerson() }
|
206
|
+
context "Before a demographic has been loaded" do
|
207
|
+
subject { r.generate }
|
208
|
+
specify { expect { subject }.to raise_error }
|
209
|
+
end
|
210
|
+
context "When there is a demographic loaded" do
|
211
|
+
before(:all) {
|
212
|
+
r.demographic("Spain").add_Spanish
|
213
|
+
}
|
214
|
+
let(:people) {
|
215
|
+
people = []
|
216
|
+
1000.times{ people << r.generate }
|
217
|
+
people
|
218
|
+
}
|
219
|
+
context "Given a demographic name" do
|
220
|
+
context "That has been added to demographics" do
|
221
|
+
subject { r.generate "Spain" }
|
222
|
+
it { should_not be_nil }
|
223
|
+
it { should be_a_kind_of RandomPerson::Person }
|
224
|
+
it_behaves_like "a Person"
|
225
|
+
it { should_not satisfy {|person| people.include? person } }
|
226
|
+
end
|
227
|
+
context "That has not been added to demographics" do
|
228
|
+
subject { r.generate "Spurious" }
|
229
|
+
it { should be_nil }
|
230
|
+
end
|
231
|
+
end
|
232
|
+
context "Given a no demographic name" do
|
233
|
+
subject { r.generate }
|
234
|
+
it { should_not be_nil }
|
235
|
+
it { should be_a_kind_of RandomPerson::Person }
|
236
|
+
it_behaves_like "a Person"
|
237
|
+
it { should_not satisfy {|person| people.include? person } }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
context "When there is no demographic loaded" do
|
241
|
+
context "Given a demographic name" do
|
242
|
+
subject { r.generate "Spain" }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
describe :demographics do
|
249
|
+
let(:r) { RandomPerson() }
|
250
|
+
context "With no demographics loaded" do
|
251
|
+
subject { r.demographics }
|
252
|
+
it { should be_empty }
|
253
|
+
it { should be_a_kind_of Hash }
|
254
|
+
end
|
255
|
+
context "Given a demographic" do
|
256
|
+
context "With a name" do
|
257
|
+
before(:all) {
|
258
|
+
r.demographic("Spain").add_Spanish
|
259
|
+
}
|
260
|
+
subject { r.demographics }
|
261
|
+
it { should_not be_empty }
|
262
|
+
it { should be_a_kind_of Hash }
|
263
|
+
specify { subject.first.should be_a_kind_of Array }
|
264
|
+
specify { subject.first.first.should be_a_kind_of String }
|
265
|
+
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
266
|
+
end
|
267
|
+
context "Without a name" do
|
268
|
+
before(:all) {
|
269
|
+
r.demographic.add_Spanish
|
270
|
+
}
|
271
|
+
subject { r.demographics }
|
272
|
+
it { should_not be_empty }
|
273
|
+
it { should be_a_kind_of Hash }
|
274
|
+
specify { subject.first.should be_a_kind_of Array }
|
275
|
+
specify { subject.first.first.should be_a_kind_of String }
|
276
|
+
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
277
|
+
end
|
278
|
+
|
279
|
+
context "With options" do
|
280
|
+
context "With a named demographic" do
|
281
|
+
let(:lower){ rand(99) }
|
282
|
+
let(:upper){ rand(100 - lower) + lower }
|
283
|
+
let(:females) { rand(10) }
|
284
|
+
let(:males) { rand(10) }
|
285
|
+
before(:all) {
|
286
|
+
r.demographic("Random!", gender_ratio: [females,males] , age_lower: lower, age_upper: upper ).add_Spanish
|
287
|
+
}
|
288
|
+
subject { r.demographics }
|
289
|
+
it { should_not be_empty }
|
290
|
+
it { should be_a_kind_of Hash }
|
291
|
+
specify { subject.first.should be_a_kind_of Array }
|
292
|
+
specify { subject.first.first.should be_a_kind_of String }
|
293
|
+
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
294
|
+
specify { subject.first.last.age_lower.should == lower }
|
295
|
+
specify { subject.first.last.age_upper.should == upper }
|
296
|
+
specify { subject.first.last.gender_ratio.should == [females,males] }
|
297
|
+
end
|
298
|
+
context "Without a named demographic" do
|
299
|
+
let(:lower){ rand(99) }
|
300
|
+
let(:upper){ rand(100 - lower) + lower }
|
301
|
+
let(:females) { rand(10) }
|
302
|
+
let(:males) { rand(10) }
|
303
|
+
before(:all) {
|
304
|
+
r.demographic(gender_ratio: [females,males] , age_lower: lower, age_upper: upper ).add_Spanish
|
305
|
+
}
|
306
|
+
subject { r.demographics }
|
307
|
+
it { should_not be_empty }
|
308
|
+
it { should be_a_kind_of Hash }
|
309
|
+
specify { subject.first.should be_a_kind_of Array }
|
310
|
+
specify { subject.first.first.should be_a_kind_of String }
|
311
|
+
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
312
|
+
specify { subject.first.last.age_lower.should == lower }
|
313
|
+
specify { subject.first.last.age_upper.should == upper }
|
314
|
+
specify { subject.first.last.gender_ratio.should == [females,males] }
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "rspec"
|
4
|
+
require 'simplecov'
|
5
|
+
#require_relative "./support/helpers.rb"
|
6
|
+
|
7
|
+
SimpleCov.start
|
8
|
+
|
9
|
+
RSpec.configure do |c|
|
10
|
+
# c.include RandomPerson::Spec::Helpers
|
11
|
+
# c.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
end
|
13
|
+
|
14
|
+
spec_dir = File.expand_path( File.dirname __FILE__ )
|
15
|
+
Dir[ File.join( spec_dir, "/support/**/*.rb")].each {|f| require f}
|
16
|
+
|
17
|
+
require "logger"
|
18
|
+
lg = Logger.new STDOUT
|
19
|
+
lg.level = Logger::DEBUG
|
20
|
+
Lg = lg
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "rspec/expectations"
|
4
|
+
|
5
|
+
RSpec::Matchers.define :all_be_a_kind_of do |kind|
|
6
|
+
match do |actual|
|
7
|
+
all_kind_of? actual, kind
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_kind_of?( collection, kind )
|
11
|
+
collection.all? {|c| c.kind_of? kind }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
dir = File.dirname(__FILE__)
|
4
|
+
spec_dir = File.expand_path( File.join dir, "../../" )
|
5
|
+
|
6
|
+
require_relative File.expand_path( File.join spec_dir, "../lib/randomperson/person.rb" )
|
7
|
+
|
8
|
+
shared_examples "it cares about gender and/or age" do |opts={}|
|
9
|
+
opts.each{|k,v| opts[k] = { gender: "m", times: 5, age: rand(83)+17, }.merge( v ) }
|
10
|
+
|
11
|
+
opts.each_pair do |k,v|
|
12
|
+
context "Given a #{k.to_s.gsub("_", " ")}" do
|
13
|
+
it_should_behave_like "a name generator" , opts[k]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
shared_examples "a name generator" do |opts={}|
|
19
|
+
opts = {times: 1000, gender: "f", age: rand(100),}.merge( opts )
|
20
|
+
opts[:rgx] = /^\p{Upper}\p{Alpha}+$/x if opts[:in].nil? && opts[:rgx].nil?
|
21
|
+
describe :execute do
|
22
|
+
subject { instance.execute RandomPerson::Person.new( gender: opts[:gender], age: opts[:age] ) }
|
23
|
+
it { should_not be_nil }
|
24
|
+
|
25
|
+
opts[:times].times do |_|
|
26
|
+
opts[:rgx].nil? ? nil : it { should match opts[:rgx] }
|
27
|
+
opts[:in].nil? ? nil : it { should be_in opts[:in] }
|
28
|
+
end
|
29
|
+
end # execute
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
shared_examples "a Name class", :parent => "Name" do
|
34
|
+
|
35
|
+
describe "Generally" do
|
36
|
+
subject { instance }
|
37
|
+
it { should_not be_nil }
|
38
|
+
it { should respond_to( :execute ) }
|
39
|
+
it { should respond_to(:formats ) }
|
40
|
+
it { should respond_to( :formats_ratiod ) }
|
41
|
+
it { should respond_to(:names)}
|
42
|
+
it { should respond_to(:possibles)}
|
43
|
+
specify { subject.qualified_const_get( "Names" ).should_not be_empty }
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
describe :formats_ratiod do
|
48
|
+
subject { instance.formats_ratiod }
|
49
|
+
it { should be_a_kind_of Array }
|
50
|
+
it { should all_be_a_kind_of Range }
|
51
|
+
specify { (0..99).all?{|i| subject.index_in_range( i ).kind_of? Fixnum }.should be_true } # this should make sure that format ratios are specified properly
|
52
|
+
end
|
53
|
+
|
54
|
+
describe :names do
|
55
|
+
subject { instance.names }
|
56
|
+
it { should be_a_kind_of Array }
|
57
|
+
it { should all_be_a_kind_of String }
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
require_relative "../lib/randomperson/Names/SpanishLast.rb"
|
3
|
+
|
4
|
+
S = RandomPerson::Names::SpanishLast.new
|
5
|
+
|
6
|
+
Benchmark.bm do |b|
|
7
|
+
b.report( "+ " ) do
|
8
|
+
a = ""
|
9
|
+
1_000_000.times {
|
10
|
+
S.names.rand +
|
11
|
+
' ' +
|
12
|
+
S.names.rand
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
b.report( '#{}' ) do
|
17
|
+
a = ""
|
18
|
+
1_000_000.times {
|
19
|
+
"#{S.names.rand} #{S.names.rand}"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# this was just too slow
|
24
|
+
# b.report( "concat " ) do
|
25
|
+
# a = ""
|
26
|
+
# 1_000_000.times {
|
27
|
+
# S.names.rand.concat(' ').concat( S.names.rand )
|
28
|
+
# }
|
29
|
+
# end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def by_index( n )
|
5
|
+
self.each_with_index { |item, index| break item if index == n }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Array
|
10
|
+
def index_in_range( n )
|
11
|
+
self.each_with_index do |x, i|
|
12
|
+
return i if x === n
|
13
|
+
end
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Times = 1000_000
|
19
|
+
Formats_ratiod = [ 0..23, 24..55, 56..74, 75..90, 91..96, 97..99 ]
|
20
|
+
Formats = Formats_ratiod.map{|x| x.to_s}
|
21
|
+
|
22
|
+
Current = Hash[ (1..Formats_ratiod.length).map{|x| x.to_s.to_sym}.zip Formats ]
|
23
|
+
|
24
|
+
Ranges = Hash[ Formats_ratiod.zip Formats ]
|
25
|
+
|
26
|
+
r = []
|
27
|
+
max = Formats_ratiod.last.end + 1
|
28
|
+
Times.times {|_| r << rand( max ) }
|
29
|
+
|
30
|
+
R = r
|
31
|
+
r = nil
|
32
|
+
|
33
|
+
def current( r )
|
34
|
+
i = Formats_ratiod.index_in_range( r )
|
35
|
+
f = Current.by_index(i).last
|
36
|
+
end
|
37
|
+
|
38
|
+
def array_contender( r )
|
39
|
+
i = Formats_ratiod.index_in_range( r )
|
40
|
+
f = Formats[i]
|
41
|
+
end
|
42
|
+
|
43
|
+
def hash_with_ranges_contender( r )
|
44
|
+
f = Ranges.each_pair{|k,v| break v if k === r }
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
Benchmark.bmbm do |b|
|
49
|
+
b.report( 'a ' ) do
|
50
|
+
Times.times {|i| array_contender R[i] }
|
51
|
+
end
|
52
|
+
|
53
|
+
b.report( 'h ' ) do
|
54
|
+
Times.times {|i| array_contender R[i] }
|
55
|
+
end
|
56
|
+
|
57
|
+
b.report( "c " ) do
|
58
|
+
Times.times {|i| current R[i] }
|
59
|
+
end
|
60
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: randomperson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,7 +50,8 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2011-
|
53
|
+
date: 2011-11-15 00:00:00.000000000 +00:00
|
54
|
+
default_executable:
|
54
55
|
dependencies: []
|
55
56
|
description: ! ' RandomPerson is a port to Ruby of Perl''s Data::RandomPerson.
|
56
57
|
Use it to generate random persons given various parameters, such as country, age
|
@@ -65,10 +66,11 @@ files:
|
|
65
66
|
- .gitignore
|
66
67
|
- CHANGELOG
|
67
68
|
- Manifest
|
68
|
-
- README
|
69
|
+
- README.markdown
|
69
70
|
- Rakefile
|
70
71
|
- gem-public_cert.pem
|
71
72
|
- lib/randomperson.rb
|
73
|
+
- lib/randomperson/Loader.rb
|
72
74
|
- lib/randomperson/Names/AmericanFemaleFirst.rb
|
73
75
|
- lib/randomperson/Names/AmericanLast.rb
|
74
76
|
- lib/randomperson/Names/AmericanMaleFirst.rb
|
@@ -119,7 +121,8 @@ files:
|
|
119
121
|
- lib/randomperson/Names/WelshLast.rb
|
120
122
|
- lib/randomperson/Names/WelshMaleFirst.rb
|
121
123
|
- lib/randomperson/Names/WelshPrefix.rb
|
122
|
-
- lib/randomperson/
|
124
|
+
- lib/randomperson/Outputter.rb
|
125
|
+
- lib/randomperson/demographic.rb
|
123
126
|
- lib/randomperson/ext/Array.rb
|
124
127
|
- lib/randomperson/ext/Date.rb
|
125
128
|
- lib/randomperson/ext/Enumerable.rb
|
@@ -132,11 +135,24 @@ files:
|
|
132
135
|
- lib/randomperson/ratio.rb
|
133
136
|
- lib/randomperson/version.rb
|
134
137
|
- randomperson.gemspec
|
135
|
-
- spec/
|
138
|
+
- spec/AmericanSuffix_spec.rb
|
139
|
+
- spec/AnyLast_spec.rb
|
140
|
+
- spec/Last_and_First_Names_spec.rb
|
141
|
+
- spec/array_spec.rb
|
142
|
+
- spec/demographic_spec.rb
|
136
143
|
- spec/generator_spec.rb
|
137
144
|
- spec/name_spec.rb
|
145
|
+
- spec/randomperson_spec.rb
|
146
|
+
- spec/rspec_helper.rb
|
147
|
+
- spec/support/helpers.rb
|
148
|
+
- spec/support/matchers/all.rb
|
149
|
+
- spec/support/matchers/be_in.rb
|
150
|
+
- spec/support/shared_examples/names.rb
|
151
|
+
- test/benchmarks/concat_or_add.rb
|
152
|
+
- test/benchmarks/my_assoc_or_select.rb
|
138
153
|
- test/test_Choice.rb
|
139
154
|
- test/test_Generator.rb
|
155
|
+
has_rdoc: true
|
140
156
|
homepage: http://github.com/yb66/RandomPerson
|
141
157
|
licenses: []
|
142
158
|
post_install_message:
|
@@ -157,13 +173,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
173
|
version: '0'
|
158
174
|
requirements: []
|
159
175
|
rubyforge_project:
|
160
|
-
rubygems_version: 1.
|
176
|
+
rubygems_version: 1.6.2
|
161
177
|
signing_key:
|
162
178
|
specification_version: 3
|
163
179
|
summary: A gem for generating random persons :)
|
164
180
|
test_files:
|
165
|
-
- spec/
|
181
|
+
- spec/AmericanSuffix_spec.rb
|
182
|
+
- spec/AnyLast_spec.rb
|
183
|
+
- spec/Last_and_First_Names_spec.rb
|
184
|
+
- spec/array_spec.rb
|
185
|
+
- spec/demographic_spec.rb
|
166
186
|
- spec/generator_spec.rb
|
167
187
|
- spec/name_spec.rb
|
188
|
+
- spec/randomperson_spec.rb
|
189
|
+
- spec/rspec_helper.rb
|
190
|
+
- spec/support/helpers.rb
|
191
|
+
- spec/support/matchers/all.rb
|
192
|
+
- spec/support/matchers/be_in.rb
|
193
|
+
- spec/support/shared_examples/names.rb
|
194
|
+
- test/benchmarks/concat_or_add.rb
|
195
|
+
- test/benchmarks/my_assoc_or_select.rb
|
168
196
|
- test/test_Choice.rb
|
169
197
|
- test/test_Generator.rb
|
metadata.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
9G$�tm�KxP�8:W��M�9?t~����<�˵��6��qVS'�Q1MH1�ՃN�=˜BFV�/��
|
1
|
+
�c�G2e��C�i����w��iX�^X5��EP�q鬿[;G7˻!o�!f�<�cqc��pb�P�)�9~����q�E<�Kp�w�:�a���fA$=���|?�
|
2
|
+
�m�!9�U��mGz�����:�/N�E13�B��ɗȊfѲ_�F P[������l�I0��73�ӫ�_�[�z�N�����o�,e��t0���`����8����);��40��5Q+eV%iQ����pu���g1�F�U�L$
|