faux_data 1.0.1 → 1.1.1
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/lib/faux_data.rb +1 -1
- data/lib/faux_data/address_generator.rb +38 -35
- data/lib/faux_data/national_id_generator.rb +53 -53
- data/lib/faux_data/person_generator.rb +32 -32
- data/lib/faux_data/personal_name_generator.rb +47 -47
- metadata +4 -4
data/lib/faux_data.rb
CHANGED
@@ -3,46 +3,49 @@
|
|
3
3
|
module FauxData
|
4
4
|
class AddressGenerator
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def initialize
|
7
|
+
@city_state_zipcodes = Array.new
|
8
|
+
@street_names = Array.new
|
9
|
+
@filename_city_state_zip = File.join(File.dirname(__FILE__),'data','us','city_state_zipcode.txt')
|
10
|
+
@filename_street_names = File.join(File.dirname(__FILE__),'data','us','street_names_top_1500.txt')
|
11
|
+
end
|
12
|
+
|
13
|
+
def address
|
14
|
+
load_csz_file if @city_state_zipcodes.size < 1
|
15
|
+
load_street_file if @street_names.size < 1
|
16
|
+
street = "#{rand(9899) + 100} #{@street_names.choice[:street]}"
|
17
|
+
if rand(5) == 4 # 20 % of the time
|
18
|
+
street << ", Apt ##{(100..999).to_a.choice}"
|
11
19
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
File.open(@filename_city_state_zip,'r') do |file|
|
26
|
-
file.each do |line|
|
27
|
-
next if $. == 1 #skip header line
|
28
|
-
rec = Hash[*col_headers.zip(line.chomp.split("\t")).flatten]
|
29
|
-
@city_state_zipcodes << rec
|
30
|
-
end
|
31
|
-
end
|
20
|
+
return @city_state_zipcodes.choice.merge({:street => street.upcase.strip})
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
def load_csz_file
|
26
|
+
col_headers = %w[zip city state].map {|e| e.downcase.to_sym}
|
27
|
+
if File.readable?(@filename_city_state_zip)
|
28
|
+
File.open(@filename_city_state_zip,'r') do |file|
|
29
|
+
file.each do |line|
|
30
|
+
next if $. == 1 #skip header line
|
31
|
+
rec = Hash[*col_headers.zip(line.chomp.split("\t")).flatten]
|
32
|
+
@city_state_zipcodes << rec
|
32
33
|
end
|
34
|
+
end
|
33
35
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
36
|
+
end
|
37
|
+
def load_street_file
|
38
|
+
col_headers = %w[street occurence].map {|e| e.downcase.to_sym}
|
39
|
+
if File.readable?(@filename_street_names)
|
40
|
+
File.open(@filename_street_names,'r') do |file|
|
41
|
+
file.each do |line|
|
42
|
+
#next if $. == 1 #skip header line
|
43
|
+
rec = Hash[*col_headers.zip(line.chomp.split("\t")).flatten]
|
44
|
+
@street_names << rec
|
44
45
|
end
|
46
|
+
end
|
45
47
|
end
|
48
|
+
end
|
46
49
|
|
47
50
|
|
48
51
|
|
@@ -3,60 +3,60 @@
|
|
3
3
|
module FauxData
|
4
4
|
class NationalIdGenerator
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
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
|
59
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
60
|
|
61
61
|
|
62
62
|
end
|
@@ -9,38 +9,38 @@ require 'faux_data/national_id_generator'
|
|
9
9
|
|
10
10
|
module FauxData
|
11
11
|
class PersonGenerator
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -3,54 +3,54 @@
|
|
3
3
|
module FauxData
|
4
4
|
class PersonalNameGenerator
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
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
|
41
39
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
54
|
|
55
55
|
end
|
56
56
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faux_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Stansbury
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-07-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|