src/rs/DisplayProperties.js   B
last analyzed

Complexity

Total Complexity 36
Complexity/F 1.09

Size

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