randomperson 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/lib/randomperson/demographic.rb +38 -12
- data/lib/randomperson/ext/date.rb +3 -0
- data/lib/randomperson/ext/set.rb +2 -0
- data/lib/randomperson/ext/string.rb +0 -0
- data/lib/randomperson/loader.rb +9 -14
- data/lib/randomperson/version.rb +1 -1
- data/lib/randomperson.rb +1 -3
- data/spec/demographic_spec.rb +14 -4
- data/spec/last_and_first_names_spec.rb +6 -90
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers.rb +90 -0
- metadata +3 -2
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,24 @@
|
|
3
3
|
require_relative "./loader.rb"
|
4
4
|
require_relative "./ext/set.rb"
|
5
5
|
|
6
|
+
|
7
|
+
|
6
8
|
module RandomPerson
|
9
|
+
class Constant < String
|
10
|
+
|
11
|
+
def to_constant
|
12
|
+
names = split('::')
|
13
|
+
names.shift if names.empty? || names.first.empty?
|
14
|
+
|
15
|
+
constant = Object
|
16
|
+
names.each do |name|
|
17
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
18
|
+
end
|
19
|
+
constant
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
7
24
|
|
8
25
|
class Demographic
|
9
26
|
include Loader
|
@@ -13,8 +30,8 @@ module RandomPerson
|
|
13
30
|
|
14
31
|
attr_accessor :malefirst, :femalefirst, :last, :gender_ratio, :age_lower, :age_upper, :prefix, :suffix #,:age_ratio
|
15
32
|
|
16
|
-
def self.
|
17
|
-
@
|
33
|
+
def self.available_name_files
|
34
|
+
@available_name_files ||= Set.new
|
18
35
|
end
|
19
36
|
|
20
37
|
|
@@ -32,7 +49,7 @@ module RandomPerson
|
|
32
49
|
@age_upper = opts[:age_upper] || 115
|
33
50
|
|
34
51
|
|
35
|
-
Demographic.
|
52
|
+
Demographic.available_name_files.merge Demographic.load_names
|
36
53
|
end
|
37
54
|
|
38
55
|
|
@@ -65,6 +82,16 @@ module RandomPerson
|
|
65
82
|
w =~ /^\p{Upper}/
|
66
83
|
}
|
67
84
|
end
|
85
|
+
|
86
|
+
|
87
|
+
def require_and_add( yesses )
|
88
|
+
yesses.map {|file_name|
|
89
|
+
require file_name
|
90
|
+
Constant.new( Demographic.translate file_name )
|
91
|
+
}.each do |klass|
|
92
|
+
addklass klass
|
93
|
+
end
|
94
|
+
end
|
68
95
|
|
69
96
|
# tribe, gender, position
|
70
97
|
def method_missing( name, *args )
|
@@ -72,17 +99,16 @@ module RandomPerson
|
|
72
99
|
|
73
100
|
words = get_words( name )
|
74
101
|
|
75
|
-
nots = get_nots( words ).map{|word|
|
76
|
-
|
77
|
-
|
102
|
+
nots = get_nots( words ).map{|word|
|
103
|
+
Demographic.available_name_files.classify_true(word)
|
104
|
+
}.fold(:&)
|
78
105
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end ).each do |klass|
|
83
|
-
addklass klass
|
84
|
-
end
|
106
|
+
yesses = get_yesses( words ).map{|word|
|
107
|
+
Demographic.available_name_files.classify_true(word)
|
108
|
+
}.fold(:&)
|
85
109
|
|
110
|
+
require_and_add yesses
|
111
|
+
|
86
112
|
self # just because
|
87
113
|
end
|
88
114
|
|
data/lib/randomperson/ext/set.rb
CHANGED
File without changes
|
data/lib/randomperson/loader.rb
CHANGED
@@ -21,18 +21,11 @@ module RandomPerson
|
|
21
21
|
end
|
22
22
|
Dir.glob( fulls )
|
23
23
|
end
|
24
|
-
|
25
24
|
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
require file_name
|
31
|
-
set_of_names = File.basename( file_name, ".rb" ).split("-").map(&:capitalize).join
|
32
|
-
end
|
33
|
-
|
34
|
-
def prefix_em( collection, prefix="RandomPerson::Names::" )
|
35
|
-
collection.map{|x| "#{prefix}#{x}"}
|
25
|
+
|
26
|
+
# Changes the file name into a string useable as a constant class name
|
27
|
+
def translate( file_name, prefix="RandomPerson::Names::" )
|
28
|
+
"#{prefix}#{File.basename( file_name, ".rb" ).split("-").map(&:capitalize).join}"
|
36
29
|
end
|
37
30
|
|
38
31
|
|
@@ -41,17 +34,19 @@ module RandomPerson
|
|
41
34
|
|
42
35
|
|
43
36
|
module InstanceMethods
|
44
|
-
|
45
|
-
# this adds the classes as constants
|
37
|
+
|
46
38
|
# The patterns are there to stop other files being added by accident.
|
47
39
|
# and to load the right names into the right instance var
|
40
|
+
# @todo remove evil
|
41
|
+
# @param [#to_constant] klass
|
48
42
|
def addklass( klass, patterns=[["Male",'First'],["Female", "First"], ['Last'], ['Prefix'], ['Suffix']] )
|
49
43
|
|
50
44
|
patterns.each do |ps|
|
51
45
|
if ps.all?{|p| klass =~ /#{p}/ }
|
52
|
-
instance_variable_set( "@#{ps.join.downcase}",
|
46
|
+
instance_variable_set( "@#{ps.join.downcase}", klass.to_constant.new)
|
53
47
|
end # if
|
54
48
|
end
|
49
|
+
klass
|
55
50
|
end # addklass
|
56
51
|
|
57
52
|
end # InstanceMethods
|
data/lib/randomperson/version.rb
CHANGED
data/lib/randomperson.rb
CHANGED
@@ -5,9 +5,6 @@ module RandomPerson
|
|
5
5
|
|
6
6
|
#require all the scaffolding
|
7
7
|
|
8
|
-
require 'set'
|
9
|
-
require 'date'
|
10
|
-
|
11
8
|
require_relative './randomperson/version.rb'
|
12
9
|
require_relative './randomperson/ext/array.rb'
|
13
10
|
require_relative './randomperson/ext/date.rb'
|
@@ -63,6 +60,7 @@ module RandomPerson
|
|
63
60
|
|
64
61
|
# The last person generated.
|
65
62
|
# If a demographic name is given that is different to the last then a new person is generated. If no name is given then the last is used.
|
63
|
+
# @param [String] demo_name The key of the demographic to use, e.g "American Ladies".
|
66
64
|
def person( demo_name=nil )
|
67
65
|
person, last_demo_name =
|
68
66
|
if demo_name.nil?
|
data/spec/demographic_spec.rb
CHANGED
@@ -10,7 +10,8 @@ module RandomPerson
|
|
10
10
|
|
11
11
|
|
12
12
|
describe "available_classes" do
|
13
|
-
|
13
|
+
before(:all) { Demographic.available_name_files.clear }
|
14
|
+
subject { Demographic.available_name_files }
|
14
15
|
it { should_not be_nil }
|
15
16
|
it { should be_a_kind_of Set }
|
16
17
|
it { should be_empty }
|
@@ -24,15 +25,24 @@ module RandomPerson
|
|
24
25
|
specify { subject.map{|f| File.basename(f, ".rb")}.should include "welsh-prefix" }
|
25
26
|
end
|
26
27
|
|
27
|
-
describe "
|
28
|
+
describe "Translating" do
|
28
29
|
%w{ancient-greek-female-first german-female-first spanish-male-first welsh-prefix}.each do |name|
|
29
30
|
file_name = File.expand_path( File.join( File.dirname(__FILE__),"../lib/randomperson/names", "#{name}.rb") )
|
30
|
-
expected = name.split("-").map(&:capitalize).join
|
31
|
+
expected = "RandomPerson::Names::#{name.split("-").map(&:capitalize).join}"
|
31
32
|
it "should require and return the class name" do
|
32
|
-
Demographic.
|
33
|
+
Demographic.translate( file_name ).should == expected
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
37
|
+
|
38
|
+
describe "require_and_add" do
|
39
|
+
subject {
|
40
|
+
Demographic.new.require_and_add(Demographic.load_names)
|
41
|
+
}
|
42
|
+
it { should_not be_nil }
|
43
|
+
it { should be_a_kind_of Array }
|
44
|
+
it { should_not be_empty }
|
45
|
+
end
|
36
46
|
|
37
47
|
describe "Instatiation" do
|
38
48
|
subject { Demographic.new }
|
@@ -4,107 +4,23 @@ require "spec_helper"
|
|
4
4
|
require_relative "./support/shared_examples/names.rb"
|
5
5
|
require_relative "../lib/randomperson/person.rb"
|
6
6
|
require_relative "../lib/randomperson/demographic.rb"
|
7
|
+
require_relative "./support/helpers.rb"
|
7
8
|
|
8
9
|
module RandomPerson
|
9
10
|
module Names
|
10
|
-
|
11
|
-
available_classes = Demographic.load_names
|
12
|
-
available_classes.each do |klass|
|
13
|
-
klass = Demographic.requiring klass
|
14
|
-
|
15
|
-
k = eval "RandomPerson::Names::#{klass}"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
word = /\b\p{Upper}\p{Alpha}+?\b (?:(?:\s|-)\b\p{Upper}\p{Alpha}+?\b)?/x
|
20
|
-
hypenated_rgx = /^#{word}$/x
|
21
|
-
french_rgx = /^(?:(?: (?:\bLe\b\s) | (?:\bd[eu]\b)\s) | (?:#{word}-))? #{word}$/x
|
22
|
-
hypenated_many_rgx = /^#{word} (?:(?:\s|-)#{word})*$/x
|
23
|
-
unhypenated_rgx = /^#{word}\s#{word}?$/x
|
24
|
-
poss_unhyph = /^#{word}(?:\s#{word})?$/
|
25
|
-
thai_style = /^\b\p{Graph}+?\b$/x
|
26
|
-
default_fix = {times: 50 }
|
27
|
-
fixtures = {}
|
28
|
-
fixtures.default = default_fix
|
29
|
-
fixtures["SpanishLast"] = default_fix.merge({ rgx: /^ \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b\s (?: (?:\bde\b\s) | (?: \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b\s (?:\by\b\s)? ) )? \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b$/x })
|
30
|
-
fixtures["AmericanLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
31
|
-
fixtures["AnyLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
32
|
-
fixtures["BritishLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
33
|
-
fixtures["EnglishLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
34
|
-
fixtures["ScottishLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
35
|
-
fixtures["WelshLast"] = default_fix.merge({ rgx: poss_unhyph } )
|
36
|
-
fixtures["FrenchLast"] = default_fix.merge({ rgx: french_rgx} )
|
37
|
-
fixtures["FrenchFemaleFirst"] = default_fix.merge({ rgx: hypenated_rgx } )
|
38
|
-
fixtures["FrenchMaleFirst"] = default_fix.merge({ rgx: hypenated_rgx } )
|
39
|
-
fixtures["BasqueMaleFirst"] = default_fix.merge({ rgx: hypenated_rgx } )
|
40
|
-
fixtures["BasqueLast"] = default_fix.merge({ rgx: unhypenated_rgx } )
|
41
|
-
fixtures["ThaiRomanisedLast"] = default_fix.merge({ rgx: hypenated_rgx } )
|
42
|
-
fixtures["ThaiFemaleFirst"] = default_fix.merge({ rgx: thai_style } )
|
43
|
-
fixtures["ThaiMaleFirst"] = default_fix.merge({ rgx: thai_style} )
|
44
|
-
fixtures["ThaiLast"] = default_fix.merge({ rgx: thai_style} )
|
45
|
-
fixtures["ThaiFirst"] = default_fix.merge({ rgx: thai_style} )
|
46
|
-
fixtures["ThaiRomanisedMaleFirst"] = default_fix.merge({ rgx: hypenated_many_rgx} )
|
47
|
-
fixtures["ThaiRomanisedFemaleFirst"] = default_fix.merge({ rgx: hypenated_many_rgx} )
|
48
|
-
fixtures["AncientGreekLast"] = default_fix.merge(
|
49
|
-
{ rgx: /^\bof\b\s(?:\b\p{Alpha}+?\b(?:\s|-)){0,3}\b\p{Alpha}+?\b$/x } )
|
50
|
-
|
51
|
-
#PREFIXES
|
52
|
-
fix_fixtures = {}
|
53
|
-
fix_fixtures["FinnishPrefix"] = {
|
54
|
-
young_male: {gender: "m", age: rand(17), in: ["herra"]}, #rgx: /^\bherra\b$/x },
|
55
|
-
older_male: {gender: "m", in: ["herra", "Dr"]}, #rgx: /^\b(?:herra|Dr)\b$/x },
|
56
|
-
young_female: {gender: "f", age: rand(17), in: ["neiti"]}, #rgx: /^\bneiti\b$/x },
|
57
|
-
older_female: {gender: "f", age: rand(17), in: ["rouva", "neiti", "Dr"]} #rgx: /^\b(?:rouva)|(?:neiti)|(?:Dr)\b$/x },
|
58
|
-
}
|
59
|
-
fix_fixtures["SpanishPrefix"] = {
|
60
|
-
young_male: {gender: "m", age: rand(17), in: ["Sr."]}, #rgx: /^\bSr\b\.$/x },
|
61
|
-
older_male: {gender: "m", in: ["Sr.", "Dr."]}, #rgx: /^\b(?:[SD]r\b\.)$/x },
|
62
|
-
young_female: {gender: "f", age: rand(17), in: ["Srta."]}, #rgx: /^\bSrta\b.$/x },
|
63
|
-
older_female: {gender: "f", in: ["Dra.", "Srta.", "Sra."]}#rgx: /^[DS]rt?a\b\.$/x }
|
64
|
-
}
|
65
|
-
fix_fixtures["AmericanPrefix"] = {
|
66
|
-
young_female: {gender: "f", age: rand(17), rgx: /^\bMiss\b$/},
|
67
|
-
older_female: {gender: "f", in: ["Miss", "Mrs.", "Dr.", "Ms."]}, #rgx: /^\bM(?:(?:iss\b)|(?:(?:r?s)\b\.))$|(?:Dr\b\.$)/x },
|
68
|
-
young_male: {gender: "m", age: rand(17), in: ["Mr."]}, #rgx: /^\bMr\b\.$/},
|
69
|
-
older_male: {gender: "m", in: ["Mr.", "Dr."]},
|
70
|
-
} #rgx: /^\b[MD]r\b\.$/}, }
|
71
|
-
fix_fixtures["AmericanSuffix"] = {
|
72
|
-
young_female: {},
|
73
|
-
older_female: {},
|
74
|
-
young_male: {},
|
75
|
-
older_male: {} }
|
76
|
-
fix_fixtures["BritishPrefix"] = {
|
77
|
-
young_female: {gender: "f", age: rand(17), rgx: /^\bMiss\b$/},
|
78
|
-
older_female: {gender: "f", rgx: /^\b(?:M(?:is|r)?s)|(?:Dr)\b$/},
|
79
|
-
young_male: {gender: "m", age: rand(17), rgx: /^\bMr\b$/},
|
80
|
-
older_male: {gender: "m", rgx: /^\b[MD]r\b$/}, }
|
81
|
-
fix_fixtures["EnglishPrefix"] = fix_fixtures["ScottishPrefix"] = fix_fixtures["WelshPrefix"] = fix_fixtures["BritishPrefix"]
|
82
|
-
|
83
|
-
#SUFFIXES
|
84
|
-
fix_fixtures["BritishSuffix"] = {
|
85
|
-
young_female: {age: rand(17), gender: "f", in: [""] },
|
86
|
-
older_female: { gender: "f", in: %w( OBE MBE GBE KBE DBE CBE JP GM PhD BSc BA )},
|
87
|
-
young_male: {age: rand(17), gender: "m", in: [""] },
|
88
|
-
older_male: {gender: "m", in: %w( OBE MBE GBE KBE DBE CBE JP GM PhD BSc BA ) },
|
89
|
-
}
|
90
|
-
fix_fixtures["AmericanSuffix"] = { # strictly speaking, gender doesn't matter here, but I'll leave the test in.
|
91
|
-
young_female: {age: rand(17), gender: "f", in: [ 'Jr.', ''] + %w( I II III IV V) },
|
92
|
-
young_male: { age: rand(17), gender: "m", in: [ 'Jr.', ''] + %w( I II III IV V ) },
|
93
|
-
older_male: { gender: "m", in: [ ''] + %w( I II III IV V Sr. ) },
|
94
|
-
older_female: { gender: "f", in: [ ''] + %w( I II III IV V Sr. ) },
|
95
|
-
}
|
96
11
|
|
12
|
+
Demographic.new.require_and_add(Demographic.load_names).each do |klass|
|
13
|
+
klass = klass.split("::").last
|
97
14
|
|
98
15
|
puts "Describe #{klass}" #because rspec doesn't output this before it blow up! Sheesh!!
|
99
16
|
describe klass do
|
100
|
-
let(:instance) {
|
17
|
+
let(:instance) { RandomPerson::Constant.new("RandomPerson::Names::#{klass}").to_constant.new }
|
101
18
|
subject{ instance }
|
102
19
|
it_should_behave_like "a Name class"
|
103
20
|
if ["Prefix", "Suffix"].any?{|x| klass.include? x }
|
104
|
-
|
105
|
-
it_should_behave_like "it cares about gender and/or age", fix_fixtures[klass]
|
21
|
+
it_should_behave_like "it cares about gender and/or age", RandomPerson::Spec::Helpers.fix_fixtures[klass]
|
106
22
|
else
|
107
|
-
it_should_behave_like "a name generator", fixtures[klass]
|
23
|
+
it_should_behave_like "a name generator", RandomPerson::Spec::Helpers.fixtures[klass]
|
108
24
|
end
|
109
25
|
end # describe
|
110
26
|
end # loop
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/helpers.rb
CHANGED
@@ -8,6 +8,96 @@ module RandomPerson
|
|
8
8
|
def all_kind_of?( collection, kind )
|
9
9
|
collection.all? {|c| c.kind_of? kind }
|
10
10
|
end
|
11
|
+
|
12
|
+
Word = /\b\p{Upper}\p{Alpha}+?\b (?:(?:\s|-)\b\p{Upper}\p{Alpha}+?\b)?/x
|
13
|
+
Hypenated_rgx = /^#{Word}$/x
|
14
|
+
French_rgx = /^(?:(?: (?:\bLe\b\s) | (?:\bd[eu]\b)\s) | (?:#{Word}-))? #{Word}$/x
|
15
|
+
Hypenated_many_rgx = /^#{Word} (?:(?:\s|-)#{Word})*$/x
|
16
|
+
Unhypenated_rgx = /^#{Word}\s#{Word}?$/x
|
17
|
+
Poss_unhyph = /^#{Word}(?:\s#{Word})?$/
|
18
|
+
Thai_style = /^\b\p{Graph}+?\b$/x
|
19
|
+
Default_fix = {times: 50 }
|
20
|
+
|
21
|
+
def self.fixtures
|
22
|
+
if @fixtures.nil?
|
23
|
+
@fixtures = {}
|
24
|
+
@fixtures.default = Default_fix
|
25
|
+
@fixtures["SpanishLast"] = Default_fix.merge({ rgx: /^ \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b\s (?: (?:\bde\b\s) | (?: \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b\s (?:\by\b\s)? ) )? \b\p{Upper}(?:\p{Alpha}+-)?\p{Alpha}+?\b$/x })
|
26
|
+
@fixtures["AmericanLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
27
|
+
@fixtures["AnyLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
28
|
+
@fixtures["BritishLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
29
|
+
@fixtures["EnglishLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
30
|
+
@fixtures["ScottishLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
31
|
+
@fixtures["WelshLast"] = Default_fix.merge({ rgx: Poss_unhyph } )
|
32
|
+
@fixtures["FrenchLast"] = Default_fix.merge({ rgx: French_rgx} )
|
33
|
+
@fixtures["FrenchFemaleFirst"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
34
|
+
@fixtures["FrenchMaleFirst"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
35
|
+
@fixtures["BasqueMaleFirst"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
36
|
+
@fixtures["BasqueLast"] = Default_fix.merge({ rgx: Unhypenated_rgx } )
|
37
|
+
@fixtures["ThaiRomanisedLast"] = Default_fix.merge({ rgx: Hypenated_rgx } )
|
38
|
+
@fixtures["ThaiFemaleFirst"] = Default_fix.merge({ rgx: Thai_style } )
|
39
|
+
@fixtures["ThaiMaleFirst"] = Default_fix.merge({ rgx: Thai_style} )
|
40
|
+
@fixtures["ThaiLast"] = Default_fix.merge({ rgx: Thai_style} )
|
41
|
+
@fixtures["ThaiFirst"] = Default_fix.merge({ rgx: Thai_style} )
|
42
|
+
@fixtures["ThaiRomanisedMaleFirst"] = Default_fix.merge({ rgx: Hypenated_many_rgx} )
|
43
|
+
@fixtures["ThaiRomanisedFemaleFirst"] = Default_fix.merge({ rgx: Hypenated_many_rgx} )
|
44
|
+
@fixtures["AncientGreekLast"] = Default_fix.merge(
|
45
|
+
{ rgx: /^\bof\b\s(?:\b\p{Alpha}+?\b(?:\s|-)){0,3}\b\p{Alpha}+?\b$/x } )
|
46
|
+
end
|
47
|
+
@fixtures
|
48
|
+
end
|
49
|
+
|
50
|
+
# prefixes
|
51
|
+
def self.fix_fixtures
|
52
|
+
if @fix_fixtures.nil?
|
53
|
+
@fix_fixtures = {}
|
54
|
+
@fix_fixtures["FinnishPrefix"] = {
|
55
|
+
young_male: {gender: "m", age: rand(17), in: ["herra"]}, #rgx: /^\bherra\b$/x },
|
56
|
+
older_male: {gender: "m", in: ["herra", "Dr"]}, #rgx: /^\b(?:herra|Dr)\b$/x },
|
57
|
+
young_female: {gender: "f", age: rand(17), in: ["neiti"]}, #rgx: /^\bneiti\b$/x },
|
58
|
+
older_female: {gender: "f", age: rand(17), in: ["rouva", "neiti", "Dr"]} #rgx: /^\b(?:rouva)|(?:neiti)|(?:Dr)\b$/x },
|
59
|
+
}
|
60
|
+
@fix_fixtures["SpanishPrefix"] = {
|
61
|
+
young_male: {gender: "m", age: rand(17), in: ["Sr."]}, #rgx: /^\bSr\b\.$/x },
|
62
|
+
older_male: {gender: "m", in: ["Sr.", "Dr."]}, #rgx: /^\b(?:[SD]r\b\.)$/x },
|
63
|
+
young_female: {gender: "f", age: rand(17), in: ["Srta."]}, #rgx: /^\bSrta\b.$/x },
|
64
|
+
older_female: {gender: "f", in: ["Dra.", "Srta.", "Sra."]}#rgx: /^[DS]rt?a\b\.$/x }
|
65
|
+
}
|
66
|
+
@fix_fixtures["AmericanPrefix"] = {
|
67
|
+
young_female: {gender: "f", age: rand(17), rgx: /^\bMiss\b$/},
|
68
|
+
older_female: {gender: "f", in: ["Miss", "Mrs.", "Dr.", "Ms."]}, #rgx: /^\bM(?:(?:iss\b)|(?:(?:r?s)\b\.))$|(?:Dr\b\.$)/x },
|
69
|
+
young_male: {gender: "m", age: rand(17), in: ["Mr."]}, #rgx: /^\bMr\b\.$/},
|
70
|
+
older_male: {gender: "m", in: ["Mr.", "Dr."]},
|
71
|
+
} #rgx: /^\b[MD]r\b\.$/}, }
|
72
|
+
@fix_fixtures["AmericanSuffix"] = {
|
73
|
+
young_female: {},
|
74
|
+
older_female: {},
|
75
|
+
young_male: {},
|
76
|
+
older_male: {} }
|
77
|
+
@fix_fixtures["BritishPrefix"] = {
|
78
|
+
young_female: {gender: "f", age: rand(17), rgx: /^\bMiss\b$/},
|
79
|
+
older_female: {gender: "f", rgx: /^\b(?:M(?:is|r)?s)|(?:Dr)\b$/},
|
80
|
+
young_male: {gender: "m", age: rand(17), rgx: /^\bMr\b$/},
|
81
|
+
older_male: {gender: "m", rgx: /^\b[MD]r\b$/}, }
|
82
|
+
@fix_fixtures["EnglishPrefix"] = @fix_fixtures["ScottishPrefix"] = @fix_fixtures["WelshPrefix"] = @fix_fixtures["BritishPrefix"]
|
83
|
+
|
84
|
+
#SUFFIXES
|
85
|
+
@fix_fixtures["BritishSuffix"] = {
|
86
|
+
young_female: {age: rand(17), gender: "f", in: [""] },
|
87
|
+
older_female: { gender: "f", in: %w( OBE MBE GBE KBE DBE CBE JP GM PhD BSc BA )},
|
88
|
+
young_male: {age: rand(17), gender: "m", in: [""] },
|
89
|
+
older_male: {gender: "m", in: %w( OBE MBE GBE KBE DBE CBE JP GM PhD BSc BA ) },
|
90
|
+
}
|
91
|
+
@fix_fixtures["AmericanSuffix"] = { # strictly speaking, gender doesn't matter here, but I'll leave the test in.
|
92
|
+
young_female: {age: rand(17), gender: "f", in: [ 'Jr.', ''] + %w( I II III IV V) },
|
93
|
+
young_male: { age: rand(17), gender: "m", in: [ 'Jr.', ''] + %w( I II III IV V ) },
|
94
|
+
older_male: { gender: "m", in: [ ''] + %w( I II III IV V Sr. ) },
|
95
|
+
older_female: { gender: "f", in: [ ''] + %w( I II III IV V Sr. ) },
|
96
|
+
}
|
97
|
+
end
|
98
|
+
@fix_fixtures
|
99
|
+
end
|
100
|
+
|
11
101
|
end # Helpers
|
12
102
|
end # Spec
|
13
103
|
end # RandomPerson
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: wirble
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/randomperson/ext/hash.rb
|
136
136
|
- lib/randomperson/ext/kernel.rb
|
137
137
|
- lib/randomperson/ext/set.rb
|
138
|
+
- lib/randomperson/ext/string.rb
|
138
139
|
- lib/randomperson/generator.rb
|
139
140
|
- lib/randomperson/loader.rb
|
140
141
|
- lib/randomperson/name.rb
|