@@ -35,36 +35,156 @@ const personGenerator = {
35
35
"id_10": "Андрей"
36
36
}
37
37
}` ,
38
+ firstNameFemaleJson : `{
39
+ "count": 10,
40
+ "list": {
41
+ "id_1": "Александра",
42
+ "id_2": "Наталия",
43
+ "id_3": "Ирина",
44
+ "id_4": "Анна",
45
+ "id_5": "Екатерина",
46
+ "id_6": "Ярослава",
47
+ "id_7": "Светлана",
48
+ "id_8": "Анастасия",
49
+ "id_9": "Валентина",
50
+ "id_10": "Елена"
51
+ }
52
+ }` ,
53
+
54
+ professionMaleJson : `{
55
+ "count": 7,
56
+ "list": {
57
+ "id_1": "Слесарь",
58
+ "id_2": "Инженер",
59
+ "id_3": "Строитель",
60
+ "id_4": "Водитель",
61
+ "id_5": "Военный",
62
+ "id_6": "Автомеханик",
63
+ "id_7": "Программист"
64
+ }
65
+ }` ,
66
+
67
+ professionFeMaleJson : `{
68
+ "count": 7,
69
+ "list": {
70
+ "id_1": "Доктор",
71
+ "id_2": "Манекенщица",
72
+ "id_3": "Учитель",
73
+ "id_4": "Домохозяйка",
74
+ "id_5": "Бухгалтер",
75
+ "id_6": "Менеджер",
76
+ "id_7": "Продавец"
77
+ }
78
+ }` ,
79
+
80
+ middleNameMaleJson : `{
81
+ "count": 7,
82
+ "list": {
83
+ "id_1": "Александрович",
84
+ "id_2": "Петрович",
85
+ "id_3": "Владимирович",
86
+ "id_4": "Дмитриевич",
87
+ "id_5": "Анатольевич",
88
+ "id_6": "Константинович",
89
+ "id_7": "Сергеевич"
90
+ }
91
+ }` ,
92
+
93
+ middleNameFeMaleJson : `{
94
+ "count": 7,
95
+ "list": {
96
+ "id_1": "Александровна",
97
+ "id_2": "Петровна",
98
+ "id_3": "Владимировна",
99
+ "id_4": "Дмитриевна",
100
+ "id_5": "Анатольевна",
101
+ "id_6": "Константиновна",
102
+ "id_7": "Сергеевна"
103
+ }
104
+ }` ,
38
105
39
106
GENDER_MALE : 'Мужчина' ,
40
107
GENDER_FEMALE : 'Женщина' ,
41
108
42
- randomIntNumber : ( max = 1 , min = 0 ) => Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ,
43
109
110
+ randomIntNumber : ( max = 1 , min = 0 ) => Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ,
111
+
44
112
randomValue : function ( json ) {
45
113
const obj = JSON . parse ( json ) ;
46
114
const prop = `id_${ this . randomIntNumber ( obj . count , 1 ) } ` ; // this = personGenerator
47
115
return obj . list [ prop ] ;
48
116
} ,
49
117
50
- randomFirstName : function ( ) {
118
+ randomFirstNameMale : function ( ) {
51
119
52
120
return this . randomValue ( this . firstNameMaleJson ) ;
121
+ } ,
53
122
123
+ randomMiddleNameMale : function ( ) {
124
+ return this . randomValue ( this . middleNameMaleJson ) ;
54
125
} ,
55
126
127
+ randomProfessionMale : function ( ) {
128
+ return this . randomValue ( this . professionMaleJson ) ;
129
+ } ,
56
130
57
- randomSurname : function ( ) {
131
+ randomFirstNameFeMale : function ( ) {
132
+ return this . randomValue ( this . firstNameFemaleJson ) ;
133
+ } ,
58
134
135
+ randomMiddleNameFemale : function ( ) {
136
+ return this . randomValue ( this . middleNameFeMaleJson ) ;
137
+ } ,
138
+
139
+ randomProfessionFeMale : function ( ) {
140
+ return this . randomValue ( this . professionFeMaleJson ) ;
141
+ } ,
142
+
143
+
144
+ randomSurname : function ( ) {
59
145
return this . randomValue ( this . surnameJson ) ;
146
+ } ,
60
147
148
+ randomGender : function ( ) {
149
+ return ( this . randomIntNumber ( 1 , 0 ) === 0 ) ? this . GENDER_FEMALE : this . GENDER_MALE
61
150
} ,
62
151
152
+ randomBirthDate : function ( min , max ) {
153
+ if ( min instanceof Date ) {
154
+ min = min . getTime ( ) ;
155
+ }
156
+
157
+ if ( max instanceof Date ) {
158
+ max = max . getTime ( ) ;
159
+ }
160
+
161
+ const r = this . randomIntNumber ( max , min ) ;
162
+
163
+ return new Date ( r )
164
+ } ,
165
+
63
166
64
167
getPerson : function ( ) {
65
168
this . person = { } ;
66
- // this.person.gender = this.randomGender();
67
- this . person . firstName = this . randomFirstName ( ) ;
169
+ this . person . gender = this . randomGender ( ) ;
170
+ this . person . surname = this . randomSurname ( ) ;
171
+ if ( this . person . gender == this . GENDER_FEMALE ) {
172
+ this . person . surname += 'а' ;
173
+ this . person . firstName = this . randomFirstNameFeMale ( ) ;
174
+ this . person . profession = this . randomProfessionFeMale ( ) ;
175
+ this . person . middleName = this . randomMiddleNameFemale ( ) ;
176
+ } else {
177
+ this . person . firstName = this . randomFirstNameMale ( ) ;
178
+ this . person . profession = this . randomProfessionMale ( ) ;
179
+ this . person . middleName = this . randomMiddleNameMale ( ) ;
180
+ }
181
+ var now = new Date ( ) ;
182
+ this . person . birthday = this . randomBirthDate (
183
+ new Date ( now . getFullYear ( ) - 70 , now . getMonth ( ) , now . getDate ( ) ) ,
184
+ new Date ( now . getFullYear ( ) - 18 , now . getMonth ( ) , now . getDate ( ) )
185
+ ) ;
186
+
187
+
68
188
return this . person ;
69
189
}
70
190
} ;
0 commit comments