Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

src/rs/DisplayProperties.js   B

Complexity

Total Complexity 36
Complexity/F 1.09

Size

Lines of Code 374
Function Count 33

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 4
dl 0
loc 374
rs 8.8
wmc 36
mnd 1
bc 36
fnc 33
bpm 1.0909
cpm 1.0909
noi 3
1
module.exports = function(GedcomX){
2
  
3
  var utils = require('../utils'),
4
      Base = require('../Base');
5
  
6
  /**
7
   * A set of properties for convenience in displaying a summary of a person to a user. 
8
   * 
9
   * @constructor
10
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
11
   */
12
  var DisplayProperties = function(json){
13
    
14
    // Protect against forgetting the new keyword when calling the constructor
15
    if(!(this instanceof DisplayProperties)){
16
      return new DisplayProperties(json);
17
    }
18
    
19
    // If the given object is already an instance then just return it. DON'T copy it.
20
    if(DisplayProperties.isInstance(json)){
21
      return json;
22
    }
23
    
24
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
25
  };
26
  
27
  DisplayProperties.prototype = Object.create(Base.prototype);
28
  
29
  DisplayProperties._gedxClass = DisplayProperties.prototype._gedxClass = 'GedcomX.DisplayProperties';
30
  
31
  DisplayProperties.jsonProps = [
32
    'name',
33
    'gender',
34
    'lifespan',
35
    'birthDate',
36
    'birthPlace',
37
    'deathDate',
38
    'deathPlace',
39
    'marriageDate',
40
    'marriagePlace',
41
    'ascendancyNumber',
42
    'descendancyNumber',
43
    'familiesAsParent',
44
    'familiesAsChild'
45
  ];
46
  
47
  /**
48
   * Check whether the given object is an instance of this class.
49
   * 
50
   * @param {Object} obj
51
   * @returns {Boolean}
52
   */
53
  DisplayProperties.isInstance = function(obj){
54
    return utils.isInstance(obj, this._gedxClass);
55
  };
56
57
  /**
58
   * Initialize from JSON
59
   * 
60
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
61
   * @return {DisplayProperties} this
62
   */
63
  DisplayProperties.prototype.init = function(json){
64
    
65
    Base.prototype.init.call(this, json);
66
    
67
    if(json){
68
      this.setName(json.name);
69
      this.setGender(json.gender);
70
      this.setLifespan(json.lifespan);
71
      this.setBirthDate(json.birthDate);
72
      this.setBirthPlace(json.birthPlace);
73
      this.setDeathDate(json.deathDate);
74
      this.setDeathPlace(json.deathPlace);
75
      this.setMarriageDate(json.marriageDate);
76
      this.setMarriagePlace(json.marriagePlace);
77
      this.setAscendancyNumber(json.ascendancyNumber);
78
      this.setDescendancyNumber(json.descendancyNumber);
79
      this.setFamiliesAsParent(json.familiesAsParent);
80
      this.setFamiliesAsChild(json.familiesAsChild);
81
    }
82
    return this;
83
  };
84
  
85
  /**
86
   * Set the name
87
   * 
88
   * @param {String} name
89
   * @return {DisplayProperties} this instance
90
   */
91
  DisplayProperties.prototype.setName = function(name){
92
    this.name = name;
93
    return this;
94
  };
95
  
96
  /**
97
   * Get the name
98
   * 
99
   * @return {String} name
100
   */
101
  DisplayProperties.prototype.getName = function(){
102
    return this.name;
103
  };
104
  
105
  /**
106
   * Set the gender
107
   * 
108
   * @param {String} gender
109
   * @return {DisplayProperties} this instance
110
   */
111
  DisplayProperties.prototype.setGender = function(gender){
112
    this.gender = gender;
113
    return this;
114
  };
115
  
116
  /**
117
   * Get the gender
118
   * 
119
   * @return {String} gender
120
   */
121
  DisplayProperties.prototype.getGender = function(){
122
    return this.gender;
123
  };
124
  
125
  /**
126
   * Set the lifespan
127
   * 
128
   * @param {String} lifespan
129
   * @return {DisplayProperties} this instance
130
   */
131
  DisplayProperties.prototype.setLifespan = function(lifespan){
132
    this.lifespan = lifespan;
133
    return this;
134
  };
135
  
136
  /**
137
   * Get the lifespan
138
   * 
139
   * @return {String} lifespan
140
   */
141
  DisplayProperties.prototype.getLifespan = function(){
142
    return this.lifespan;
143
  };
144
  
145
  /**
146
   * Set the birth date
147
   * 
148
   * @param {String} birthDate
149
   * @return {DisplayProperties} this instance
150
   */
151
  DisplayProperties.prototype.setBirthDate = function(birthDate){
152
    this.birthDate = birthDate;
153
    return this;
154
  };
155
  
156
  /**
157
   * Get the birth date
158
   * 
159
   * @return {String} birthDate
160
   */
161
  DisplayProperties.prototype.getBirthDate = function(){
162
    return this.birthDate;
163
  };
164
  
165
  /**
166
   * Set the birth place
167
   * 
168
   * @param {String} birthPlace
169
   * @return {DisplayProperties} this instance
170
   */
171
  DisplayProperties.prototype.setBirthPlace = function(birthPlace){
172
    this.birthPlace = birthPlace;
173
    return this;
174
  };
175
  
176
  /**
177
   * Get the birth place
178
   * 
179
   * @return {String} birthPlace
180
   */
181
  DisplayProperties.prototype.getBirthPlace = function(){
182
    return this.birthPlace;
183
  };
184
  
185
  /**
186
   * Set the death date
187
   * 
188
   * @param {String} deathDate
189
   * @return {DisplayProperties} this instance
190
   */
191
  DisplayProperties.prototype.setDeathDate = function(deathDate){
192
    this.deathDate = deathDate;
193
    return this;
194
  };
195
  
196
  /**
197
   * Get the death date
198
   * 
199
   * @return {String} deathDate
200
   */
201
  DisplayProperties.prototype.getDeathDate = function(){
202
    return this.deathDate;
203
  };
204
  
205
  /**
206
   * Set the death place
207
   * 
208
   * @param {String} deathPlace
209
   * @return {DisplayProperties} this instance
210
   */
211
  DisplayProperties.prototype.setDeathPlace = function(deathPlace){
212
    this.deathPlace = deathPlace;
213
    return this;
214
  };
215
  
216
  /**
217
   * Get the death place
218
   * 
219
   * @return {String} deathPlace
220
   */
221
  DisplayProperties.prototype.getDeathPlace = function(){
222
    return this.deathPlace;
223
  };
224
  
225
  /**
226
   * Set the marriage date
227
   * 
228
   * @param {String} marriageDate
229
   * @return {DisplayProperties} this instance
230
   */
231
  DisplayProperties.prototype.setMarriageDate = function(marriageDate){
232
    this.marriageDate = marriageDate;
233
    return this;
234
  };
235
  
236
  /**
237
   * Get the marriage date
238
   * 
239
   * @return {String} marriageDate
240
   */
241
  DisplayProperties.prototype.getMarriageDate = function(){
242
    return this.marriageDate;
243
  };
244
  
245
  /**
246
   * Set the marriage place
247
   * 
248
   * @param {String} marriagePlace
249
   * @return {DisplayProperties} this instance
250
   */
251
  DisplayProperties.prototype.setMarriagePlace = function(marriagePlace){
252
    this.marriagePlace = marriagePlace;
253
    return this;
254
  };
255
  
256
  /**
257
   * Get the marriage place
258
   * 
259
   * @return {String} marriagePlace
260
   */
261
  DisplayProperties.prototype.getMarriagePlace = function(){
262
    return this.marriagePlace;
263
  };
264
  
265
  /**
266
   * Set the ascendancy number
267
   * 
268
   * @param {String} ascendancyNumber
269
   * @return {DisplayProperties} this instance
270
   */
271
  DisplayProperties.prototype.setAscendancyNumber = function(ascendancyNumber){
272
    this.ascendancyNumber = ascendancyNumber;
273
    return this;
274
  };
275
  
276
  /**
277
   * Get the ascendancy number
278
   * 
279
   * @return {String} ascendancyNumber
280
   */
281
  DisplayProperties.prototype.getAscendancyNumber = function(){
282
    return this.ascendancyNumber;
283
  };
284
  
285
  /**
286
   * Set the descendancy number
287
   * 
288
   * @param {String} descendancyNumber
289
   * @return {DisplayProperties} this instance
290
   */
291
  DisplayProperties.prototype.setDescendancyNumber = function(descendancyNumber){
292
    this.descendancyNumber = descendancyNumber;
293
    return this;
294
  };
295
  
296
  /**
297
   * Get the descendancy number
298
   * 
299
   * @return {String} descendancyNumber
300
   */
301
  DisplayProperties.prototype.getDescendancyNumber = function(){
302
    return this.descendancyNumber;
303
  };
304
  
305
  /**
306
   * Set families as parent
307
   * 
308
   * @param {FamilyView[]} families
309
   * @return {DisplayProperties} this instance
310
   */
311
  DisplayProperties.prototype.setFamiliesAsParent = function(families){
312
    return this._setArray(families, 'familiesAsParent', 'addFamilyAsParent');
313
  };
314
  
315
  /**
316
   * Add a family as parent
317
   * 
318
   * @param {FamilyView} family
319
   * @return {DisplayProperties} this instance
320
   */
321
  DisplayProperties.prototype.addFamilyAsParent = function(family){
322
    return this._arrayPush(family, 'familiesAsParent', GedcomX.FamilyView);
323
  };
324
  
325
  /**
326
   * Get families as parent
327
   * 
328
   * @return {FamilyView[]} families
329
   */
330
  DisplayProperties.prototype.getFamiliesAsParent = function(){
331
    return this.familiesAsParent || [];
332
  };
333
  
334
  /**
335
   * Set families as child
336
   * 
337
   * @param {FamilyView[]} families
338
   * @return {DisplayProperties} this instance
339
   */
340
  DisplayProperties.prototype.setFamiliesAsChild = function(families){
341
    return this._setArray(families, 'familiesAsChild', 'addFamilyAsChild');
342
  };
343
  
344
  /**
345
   * Add a family as child
346
   * 
347
   * @param {FamilyView} family
348
   * @return {DisplayProperties} this instance
349
   */
350
  DisplayProperties.prototype.addFamilyAsChild = function(family){
351
    return this._arrayPush(family, 'familiesAsChild', GedcomX.FamilyView);
352
  };
353
  
354
  /**
355
   * Get families as child
356
   * 
357
   * @return {FamilyView[]} families
358
   */
359
  DisplayProperties.prototype.getFamiliesAsChild = function(){
360
    return this.familiesAsChild || [];
361
  };
362
  
363
  /**
364
   * Export the object as JSON
365
   * 
366
   * @return {Object} JSON object
367
   */
368
  DisplayProperties.prototype.toJSON = function(){
369
    return this._toJSON(Base, DisplayProperties.jsonProps);
370
  };
371
  
372
  GedcomX.DisplayProperties = DisplayProperties;
373
  
374
};