faux_data 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.
- data/LICENSE +8 -0
- data/README.md +45 -0
- data/Rakefile +19 -0
- data/lib/faux_data.rb +9 -0
- data/lib/faux_data/address_generator.rb +50 -0
- data/lib/faux_data/data/us/city_state_zipcode.txt +42193 -0
- data/lib/faux_data/data/us/female_given_names.txt +4275 -0
- data/lib/faux_data/data/us/male_given_names.txt +1219 -0
- data/lib/faux_data/data/us/state_list.txt +42193 -0
- data/lib/faux_data/data/us/state_list.zip +0 -0
- data/lib/faux_data/data/us/street_names_top_1500.txt +1500 -0
- data/lib/faux_data/data/us/surnames.txt +81503 -0
- data/lib/faux_data/national_id_generator.rb +63 -0
- data/lib/faux_data/person_generator.rb +47 -0
- data/lib/faux_data/personal_name_generator.rb +56 -0
- data/test/test_national_id_generator.rb +34 -0
- data/test/test_person.rb +39 -0
- metadata +83 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module FauxData
|
|
4
|
+
class NationalIdGenerator
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def initialize(opts = {})
|
|
8
|
+
options = {
|
|
9
|
+
:country_code => 'us'
|
|
10
|
+
}.merge(opts)
|
|
11
|
+
@country_code = options[:country_code]
|
|
12
|
+
@@consumed_national_ids = Array.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def national_id
|
|
17
|
+
id = ''
|
|
18
|
+
while (not valid_national_id_us?(id))
|
|
19
|
+
id = generate_national_id_us if @country_code == 'us'
|
|
20
|
+
#pp id
|
|
21
|
+
end
|
|
22
|
+
@@consumed_national_ids << id
|
|
23
|
+
return id
|
|
24
|
+
end
|
|
25
|
+
def national_ids
|
|
26
|
+
ids = Array.new
|
|
27
|
+
ids.replace @@consumed_national_ids
|
|
28
|
+
return ids
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def generate_national_id_us
|
|
34
|
+
ssn = "#{rand(1000).to_s.rjust(3,'0')}-#{rand(100).to_s.rjust(2,'0')}-#{rand(10000).to_s.rjust(4,'0')}"
|
|
35
|
+
return ssn
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Test to see if valid SSN using IRS rules on SSN
|
|
40
|
+
#
|
|
41
|
+
# SSN can be broken down into Area, Group, and Serial Number as AAA-GG-SSSS
|
|
42
|
+
#
|
|
43
|
+
# Area Numbers: excluding area numbers 000, 666 and 900-999.
|
|
44
|
+
# Group Numbers: SSN randomization will not assign group number 00
|
|
45
|
+
# Serial NUmbers: SSN randomization will not assign serial number 0000.
|
|
46
|
+
# SSNs containing group number 00 or serial number 0000 will continue to be invalid.
|
|
47
|
+
#
|
|
48
|
+
def valid_national_id_us?(ssn)
|
|
49
|
+
return false if @@consumed_national_ids.include?(ssn)
|
|
50
|
+
ssn = ssn.delete('-')
|
|
51
|
+
return false if not ssn =~ /^(\d){9}$/ #test for 9 digits
|
|
52
|
+
ssn = Hash[* [:area, :group, :serial].zip(ssn.unpack("A3A2A4")).flatten]
|
|
53
|
+
return false if ssn[:group] == '00'
|
|
54
|
+
return false if ssn[:serial] == '0000'
|
|
55
|
+
return false if ssn[:area] == '000'
|
|
56
|
+
return false if ssn[:area] == '666'
|
|
57
|
+
return false if ssn[:area].to_i >= 900 and ssn[:area].to_i <=999
|
|
58
|
+
return true
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
require File.join(File.dirname(__FILE__),'personal_name_generator')
|
|
4
|
+
require File.join(File.dirname(__FILE__),'address_generator')
|
|
5
|
+
require File.join(File.dirname(__FILE__),'national_id_generator')
|
|
6
|
+
require 'date'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module FauxData
|
|
11
|
+
class PersonGenerator
|
|
12
|
+
def initialize
|
|
13
|
+
@name = PersonalNameGenerator.new
|
|
14
|
+
@address = AddressGenerator.new
|
|
15
|
+
@national_id = NationalIdGenerator.new(:county_code => 'us')
|
|
16
|
+
@max_age_in_days = (365.2524 * 100).to_i
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def person
|
|
20
|
+
sex = pick_sex()
|
|
21
|
+
address = @address.address
|
|
22
|
+
person = address.merge({
|
|
23
|
+
:sex => sex,
|
|
24
|
+
:surname => @name.surname,
|
|
25
|
+
:first_name => sex == :male ? @name.given_name_male : @name.given_name_female,
|
|
26
|
+
:middle_name => sex == :male ? @name.given_name_male : @name.given_name_female,
|
|
27
|
+
:ssn => @national_id.national_id,
|
|
28
|
+
:date_of_birth => Date.today - (rand(@max_age_in_days))
|
|
29
|
+
})
|
|
30
|
+
person[:email] = "#{person[:first_name].strip.downcase}.#{person[:surname].strip.downcase}@" + pick_email_domain()
|
|
31
|
+
return person
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def pick_sex
|
|
38
|
+
return [:male, :female].choice
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def pick_email_domain
|
|
42
|
+
return %w[ example.com example.net example.org].choice
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module FauxData
|
|
4
|
+
class PersonalNameGenerator
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@surnames = Array.new
|
|
8
|
+
@given_names_female = Array.new
|
|
9
|
+
@given_names_male = Array.new
|
|
10
|
+
@filename_surnames = File.join(File.dirname(__FILE__),'data','us','surnames.txt')
|
|
11
|
+
@filename_given_names_female = File.join(File.dirname(__FILE__),'data','us','female_given_names.txt')
|
|
12
|
+
@filename_given_names_male = File.join(File.dirname(__FILE__),'data','us','male_given_names.txt')
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def surname
|
|
17
|
+
load_surname if @surnames.size < 1
|
|
18
|
+
return @surnames.choice
|
|
19
|
+
end
|
|
20
|
+
def given_name_female
|
|
21
|
+
load_given_names_female if @given_names_female.size < 1
|
|
22
|
+
return @given_names_female.choice
|
|
23
|
+
end
|
|
24
|
+
def given_name_male
|
|
25
|
+
load_given_names_male if @given_names_male.size < 1
|
|
26
|
+
return @given_names_male.choice
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
def load_name_file(filename)
|
|
34
|
+
names = Array.new
|
|
35
|
+
if File.readable?(filename)
|
|
36
|
+
File.open(filename,'r') do |file|
|
|
37
|
+
file.each do |line|
|
|
38
|
+
names << line[0,15].strip
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
names << "" if names.size == 0
|
|
43
|
+
return names
|
|
44
|
+
end
|
|
45
|
+
def load_surname
|
|
46
|
+
@surnames = load_name_file(@filename_surnames)
|
|
47
|
+
end
|
|
48
|
+
def load_given_names_female
|
|
49
|
+
@given_names_female = load_name_file(@filename_given_names_female)
|
|
50
|
+
end
|
|
51
|
+
def load_given_names_male
|
|
52
|
+
@given_names_male = load_name_file(@filename_given_names_male)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'pp'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
require File.join(File.dirname(__FILE__),'..','lib','faux_data')
|
|
8
|
+
|
|
9
|
+
class Test_SSN_Creation < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
end
|
|
13
|
+
def teardown
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_ssn_creation
|
|
17
|
+
nid = FauxData::NationalIdGenerator.new(:country_code => 'us')
|
|
18
|
+
id = nid.national_id
|
|
19
|
+
assert_equal(11,id.to_s.size,"SSN lenth should equal 11 with two (2) hypens and nine (9) digits: ssn [#{id}]")
|
|
20
|
+
assert_equal(9,id.to_s.delete("-").size,"SSN lenth should have length of 9 chars")
|
|
21
|
+
assert(id.to_s.delete("-") =~ /^\d{9}$/ ,"SSN lenth should equal nine (9) digits")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_ssn_tracking
|
|
25
|
+
nid = FauxData::NationalIdGenerator.new(:country_code => 'us')
|
|
26
|
+
ids = Array.new
|
|
27
|
+
(1..100).each do |i|
|
|
28
|
+
id = nid.national_id
|
|
29
|
+
ids << id
|
|
30
|
+
end
|
|
31
|
+
assert_equal(ids.size, nid.national_ids.size, "Both arrays should contain 100 elements ")
|
|
32
|
+
assert(ids == nid.national_ids, "Both arrays should contain the same 100 elements ")
|
|
33
|
+
end
|
|
34
|
+
end
|
data/test/test_person.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'pp'
|
|
5
|
+
require 'awesome_print'
|
|
6
|
+
require 'date'
|
|
7
|
+
|
|
8
|
+
require File.join(File.dirname(__FILE__),'..','lib','faux_data')
|
|
9
|
+
|
|
10
|
+
class Test_Person_Creation < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
end
|
|
14
|
+
def teardown
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_person_creation
|
|
18
|
+
required_keys = %w[ssn surname first_name middle_name street city state zip date_of_birth].map {|i| i.downcase.to_sym}
|
|
19
|
+
pg = FauxData::PersonGenerator.new
|
|
20
|
+
person = pg.person
|
|
21
|
+
assert(person.is_a?(Hash), "Person should be a hash")
|
|
22
|
+
required_keys.each do |k|
|
|
23
|
+
assert(person.key?(k), "Should have this key: #{k}")
|
|
24
|
+
end
|
|
25
|
+
assert(person[:date_of_birth].is_a?(Date), "Date of Birth should be a date object")
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_ssn_tracking
|
|
30
|
+
pg = FauxData::PersonGenerator.new
|
|
31
|
+
persons = Array.new
|
|
32
|
+
(1..100).each do |i|
|
|
33
|
+
person = pg.person
|
|
34
|
+
persons << person
|
|
35
|
+
end
|
|
36
|
+
assert_equal(100 , persons.size , "Both arrays should contain 100 elements ")
|
|
37
|
+
ap persons
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: faux_data
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 23
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 1
|
|
8
|
+
- 0
|
|
9
|
+
- 0
|
|
10
|
+
version: 1.0.0
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Chris Stansbury
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2012-03-10 00:00:00 -06:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: FauxData was created to quickly generate random employee demographic data which is used for demostrating your application and application's reporting features. Address data is pulled from US Census records, keeping the US city, US state, and US zip code in sync, while street names are randomly pulled.
|
|
23
|
+
email: Chris@koozie.org
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- Rakefile
|
|
32
|
+
- lib/faux_data/address_generator.rb
|
|
33
|
+
- lib/faux_data/data/us/city_state_zipcode.txt
|
|
34
|
+
- lib/faux_data/data/us/female_given_names.txt
|
|
35
|
+
- lib/faux_data/data/us/male_given_names.txt
|
|
36
|
+
- lib/faux_data/data/us/state_list.txt
|
|
37
|
+
- lib/faux_data/data/us/state_list.zip
|
|
38
|
+
- lib/faux_data/data/us/street_names_top_1500.txt
|
|
39
|
+
- lib/faux_data/data/us/surnames.txt
|
|
40
|
+
- lib/faux_data/national_id_generator.rb
|
|
41
|
+
- lib/faux_data/person_generator.rb
|
|
42
|
+
- lib/faux_data/personal_name_generator.rb
|
|
43
|
+
- lib/faux_data.rb
|
|
44
|
+
- test/test_national_id_generator.rb
|
|
45
|
+
- test/test_person.rb
|
|
46
|
+
- README.md
|
|
47
|
+
- LICENSE
|
|
48
|
+
has_rdoc: true
|
|
49
|
+
homepage: https://github.com/koozie/FauxData
|
|
50
|
+
licenses: []
|
|
51
|
+
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
hash: 3
|
|
63
|
+
segments:
|
|
64
|
+
- 0
|
|
65
|
+
version: "0"
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
hash: 3
|
|
72
|
+
segments:
|
|
73
|
+
- 0
|
|
74
|
+
version: "0"
|
|
75
|
+
requirements: []
|
|
76
|
+
|
|
77
|
+
rubyforge_project:
|
|
78
|
+
rubygems_version: 1.3.7
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 3
|
|
81
|
+
summary: FauxData is a ruby library that creates faux employee, member or people data
|
|
82
|
+
test_files: []
|
|
83
|
+
|