-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.rb
146 lines (132 loc) · 4.16 KB
/
generator.rb
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
145
146
def openLocaleFile fileName
data={}
i=0
File.readlines(fileName).map do |line|
arr=line.to_s.gsub("\n", "").gsub("\r", "")
data[i]=arr
i=i+1
end
return data
end
locale=ARGV[0]
puts locale
counter=ARGV[1].to_i
mistakeChance=ARGV[2] ? (ARGV[2].to_f >= 0 ? ARGV[2].to_f : (raise 'Number of mistakes must be positive.')) : 0
mistakeNumber=mistakeChance*counter
remainder=mistakeNumber%counter
timesNumber=(mistakeNumber/counter).to_i
if locale=="ru_RU"
country="Россия"
$sub="абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ0123456789"
$addPrefix=", д."
elsif locale=="by_BY"
country="Беларусь"
$sub="АаБбВвГгДдЕеЁёЖжЗзІіЙйКкЛлМмНнОоПпРрСсТтУуЎўФфХхЦцЧчШшЫыЬьЭэЮюЯя0123456789"
$addPrefix=", д."
elsif locale=="en_US"
country="Unates States"
$sub="abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789"
$addPrefix=", fl."
elsif locale=="en_GB"
country="Great Britain"
$sub="abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789"
$addPrefix=", h."
end
$states=openLocaleFile("locale/"+locale+"/states.yml")
$cities=openLocaleFile("locale/"+locale+"/cities.yml")
$streets=openLocaleFile("locale/"+locale+"/streets.yml")
$firstname_m=openLocaleFile("locale/"+locale+"/firstname_m.yml")
$firstname_f=openLocaleFile("locale/"+locale+"/firstname_f.yml")
$lastname_m=openLocaleFile("locale/"+locale+"/lastname_m.yml")
$lastname_f=openLocaleFile("locale/"+locale+"/lastname_f.yml")
$phones=openLocaleFile("locale/"+locale+"/phones.yml")
if !File.file?("locale/"+locale+"/middlename_m.yml") || !File.file?("locale/"+locale+"/middlename_f.yml")
$middlename_m=""
$middlename_f=""
else
$middlename_m=openLocaleFile("locale/"+locale+"/middlename_m.yml")
$middlename_f=openLocaleFile("locale/"+locale+"/middlename_f.yml")
end
def mistakeString str
#Uncomment to check the correctness of making mistakes
#puts str + " -- mistake here"
cc=Random.rand(3)
case cc
when 0
letter1=Random.rand(str.length)
letter2=Random.rand(str.length)
temp=str[letter1]
str[letter1]=str[letter2]
str[letter2]=temp
when 1
str[Random.rand(str.length)+1]=''
when 2
str.insert Random.rand(str.length), $sub[Random.rand($sub.length)]
end
return str
end
def chooseMistake name, state, city, street, phone, country
c=Random.rand(6)
case c
when 0
name=mistakeString(name)
when 1
state=mistakeString(state)
when 2
city=mistakeString(city)
when 3
street=mistakeString(street)
when 4
phone=mistakeString(phone)
when 5
country=mistakeString(country)
end
end
def chooseName
c=Random.rand(2)
case c
when 0
name=$lastname_m[Random.rand($lastname_m.size)] + " " + $firstname_m[Random.rand($firstname_m.size)] + ($middlename_m.size>0 ? " " + $middlename_m[Random.rand($middlename_m.size)] : "")
when 1
name=$lastname_f[Random.rand($lastname_f.size)] + " " + $firstname_f[Random.rand($firstname_f.size)] + ($middlename_f.size>0 ? " " + $middlename_f[Random.rand($middlename_f.size)] : "")
end
return name
end
def chooseState
state=$states[Random.rand($states.size)]
return state
end
def chooseCity
city=$cities[Random.rand($cities.size)]
return city
end
def chooseStreet
street=$streets[Random.rand($streets.size)] + $addPrefix + Random.rand(500).to_s
return street
end
def choosePhone
phone=$phones[Random.rand($phones.size)] + Random.rand(1000).to_s
return phone
end
counter.times do |i|
name=chooseName
state=chooseState
city=chooseCity
street=chooseStreet
phone=choosePhone
currentCountry=country
if(mistakeNumber >= counter)
timesNumber.to_i.times do
chooseMistake(name, state, city, street, phone, currentCountry)
end
if(remainder>0)
chooseMistake(name, state, city, street, phone, currentCountry)
remainder=remainder-1
end
else
if(i<mistakeNumber)
chooseMistake(name, state, city, street, phone, currentCountry)
end
end
puts name + "; " + currentCountry + "; " + state + "; " + city + "; " + street + "; " + phone
end