Repository navigation
Expand file tree
/
Copy pathdatagenerator.rb
More file actions
145 lines (140 loc) · 3.59 KB
/
Copy pathdatagenerator.rb
File metadata and controls
145 lines (140 loc) · 3.59 KB
1
2
3
4
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env ruby -w
require 'date'
##############################################################
#DataGenerator Class
# This is a test data generator class I use to generate
# test data that looks like real data.
##############################################################
class DataGenerator
def initialize
logfile = File.new("DataGenerator.log","a")
logfile.write("Executing generator at #{Time.now}\n")
@firstNames = ["Bob", "Carol", "Ted", "Alice"]
@lastNames = ["Smith", "Jones", "Campbell", "Edwards"]
@delimiter = ":"
@streetNames = ["Pine", "Oak", "Main", "Maple"]
@streetTypes = ["St.", "Dr.", "Ave.", "Rd."]
@cities = ["Oakland", "Three Oaks", "Paradise", "Hell", "Concepcion"]
@states = ["AL","AS","AZ","AK","CA","CO"]
@products = ["oranges", "apples", "bananas", "avocados"]
@hostnames = ["anakin", "eduardo", "windu", "skywalker","arrakis"]
@domains = ["com","net","edu","gov","biz"]
if FileTest.exist?("specialFields1.dat")
@specialFields1 = File.new("specialFields1.dat","r").readlines
logfile.write("Read in specialFields.dat: values #{@specialFields1}\n")
@specialFields1.each { |item| item.chomp!}
else
@specialFields1 = []
end
@specialFields2 = []
@specialFields3 = []
@specialFields4 = []
end
def firstName
####################################################
# firstName
# returns a randomly selected item from the firstNames array
####################################################
@firstNames[rand(@firstNames.length)]
end
def lastName
@lastNames[rand(@lastNames.length)]
end
def delimiter
@delimiter
end
def streetName
@streetNames[rand(@streetNames.length)]
end
def streetType
@streetTypes[rand(@streetTypes.length)]
end
def city
@cities[rand(@cities.length)]
end
def state
@states[rand(@states.length)]
end
def product
@products[rand(@products.length)]
end
def lastNames
@lastNames
end
def firstNames
@firstNames
end
def alpha(length)
str = ''
length.times do
x = 65 + rand(26)
str = str + x.chr
end
str
end
def numeric(length)
str = ''
length.times do
x = rand(10)
str = str + x.to_s
end
str
end
def ssn
ssn1 = numeric(3)
ssn2 = numeric(2)
ssn3 = numeric(4)
ssn1 + '-' + ssn2 + '-' + ssn3
end
def phone
phn1 = numeric(3)
phn2 = numeric(3)
phn3 = numeric(4)
phn1 + '-' + phn2 + '-' + phn3
end
def zipcode
numeric(5)
end
def specialField1
if specialFields1.empty?
'specialField1'
else
specialFields1[rand(@specialFields1.length)]
end
end
def specialFields1
@specialFields1
end
def specialFields2
@specialFields2
end
def specialFields3
@specialFields3
end
def specialFields4
@specialFields4
end
def dateWithin(days)
(Date.today - rand(days)).to_s
end
def email
@firstNames[rand(@firstNames.length)] + '.' + @lastNames[rand(@lastNames.length)] + '@' + @hostnames[rand(@hostnames.length)] + '.' + @domains[rand(@domains.length)]
end
def record(fieldList)
fields = fieldList.split(/,/)
end
def address
num = rand(7)
if num == 0
num = 1
end
numeric(num) + ' ' + streetName + ' ' + streetType
end
def value(aValue)
aValue
end
def cycle(aListString)
aList = aListString.split(/,/)
aList[rand(aList.length)]
end
end