Completed
Push — master ( a4cfd2...abd258 )
by Justin
01:45
created

SourceDescription.addCoverage   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * A description of a source.
6
 * 
7
 * @constructor
8
 * @apram {Object} [json]
9
 */
10
var SourceDescription = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof SourceDescription)){
14
    return new SourceDescription(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(SourceDescription.isInstance(json)){
19
    return json;
20
  }
21
  
22
  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...
23
};
24
25
SourceDescription.prototype = Object.create(GedcomX.ExtensibleData.prototype);
26
27
SourceDescription._gedxClass = SourceDescription.prototype._gedxClass = 'GedcomX.SourceDescription';
28
29
SourceDescription.jsonProps = [
30
  'resourceType',
31
  'citations',
32
  'mediaType',
33
  'about',
34
  'mediator',
35
  'sources',
36
  'analysis',
37
  'componentOf',
38
  'titles',
39
  'notes',
40
  'attribution',
41
  'rights',
42
  'coverage',
43
  'descriptions',
44
  'identifiers',
45
  'created',
46
  'modified',
47
  'repository'
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
SourceDescription.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 {SourceDescription} this
65
 */
66
SourceDescription.prototype.init = function(json){
67
  
68
  GedcomX.ExtensibleData.prototype.init.call(this, json);
69
  
70
  if(json){
71
    this.setResourceType(json.resourceType);
72
    this.setCitations(json.citations);
73
    this.setMediaType(json.mediaType);
74
    this.setAbout(json.about);
75
    this.setMediator(json.mediator);
76
    this.setSources(json.sources);
77
    this.setAnalysis(json.analysis);
78
    this.setComponentOf(json.componentOf);
79
    this.setTitles(json.titles);
80
    this.setNotes(json.notes);
81
    this.setAttribution(json.attribution);
82
    this.setRights(json.rights);
83
    this.setCoverage(json.coverage);
84
    this.setDescriptions(json.descriptions);
85
    this.setIdentifiers(json.identifiers);
86
    this.setCreated(json.created);
87
    this.setModified(json.modified);
88
    this.setRepository(json.repository);
89
  }
90
  return this;
91
};
92
93
/**
94
 * Get the resource type
95
 * 
96
 * @returns {String}
97
 */
98
SourceDescription.prototype.getResourceType = function(){
99
  return this.resourceType;
100
};
101
102
/**
103
 * Set the resource type
104
 * 
105
 * @param {String} resourceType
106
 * @returns {SourceDescription}
107
 */
108
SourceDescription.prototype.setResourceType = function(resourceType){
109
  this.resourceType = resourceType;
110
  return this;
111
};
112
113
/**
114
 * Get the citations
115
 * 
116
 * @returns {SourceCitation[]}
117
 */
118
SourceDescription.prototype.getCitations = function(){
119
  return this.citations || [];
120
};
121
122
/**
123
 * Set the citations
124
 * 
125
 * @param {SourceCitation[]|Object[]} citations
126
 * @returns {SourceDescription}
127
 */
128
SourceDescription.prototype.setCitations = function(citations){
129
  return this._setArray(citations, 'citations', 'addCitation');
130
};
131
132
/**
133
 * Add a citation
134
 * 
135
 * @param {SourceCitation|Object} citation
136
 * @returns {SourceDescription}
137
 */
138
SourceDescription.prototype.addCitation = function(citation){
139
  return this._arrayPush(citation, 'citations', GedcomX.SourceCitation);
140
};
141
142
/**
143
 * Get the media type
144
 * 
145
 * @return {String}
146
 */
147
SourceDescription.prototype.getMediaType = function(){
148
  return this.mediaType;
149
};
150
151
/**
152
 * Set the media type
153
 * 
154
 * @param {String} mediaType
155
 * @returns {SourceDescription}
156
 */
157
SourceDescription.prototype.setMediaType = function(mediaType){
158
  this.mediaType = mediaType;
159
  return this;
160
};
161
162
/**
163
 * Get the about property
164
 * 
165
 * @returns {String}
166
 */
167
SourceDescription.prototype.getAbout = function(){
168
  return this.about;
169
};
170
171
/**
172
 * Set the about property
173
 * 
174
 * @param {String} about
175
 * @returns {SourceDescription}
176
 */
177
SourceDescription.prototype.setAbout = function(about){
178
  this.about = about;
179
  return this;
180
};
181
182
/**
183
 * Get the mediator
184
 * 
185
 * @returns {ResourceReference}
186
 */
187
SourceDescription.prototype.getMediator = function(){
188
  return this.mediator;
189
};
190
191
/**
192
 * Set the mediator
193
 * 
194
 * @param {ResourceReference} mediator
195
 * @returns {SourceDescription}
196
 */
197
SourceDescription.prototype.setMediator = function(mediator){
198
  if(mediator){
199
    this.mediator = GedcomX.ResourceReference(mediator);
200
  }
201
  return this;
202
};
203
204
/**
205
 * Get sources
206
 * 
207
 * @returns {SourceReference[]}
208
 */
209
SourceDescription.prototype.getSources = function(){
210
  return this.sources || [];
211
};
212
213
/**
214
 * Set the sources
215
 * 
216
 * @param {SourceReference[]|Object[]} sources
217
 * @returns {SourceDescription}
218
 */
219
SourceDescription.prototype.setSources = function(sources){
220
  return this._setArray(sources, 'sources', 'addSource');
221
};
222
223
/**
224
 * Add a source
225
 * 
226
 * @param {SourceReference|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
227
 * @returns {SourceDescription}
228
 */
229
SourceDescription.prototype.addSource = function(source){
230
  return this._arrayPush(source, 'sources', GedcomX.SourceReference);
231
};
232
233
/**
234
 * Get the analysis
235
 * 
236
 * @return {ResourceReference}
237
 */
238
SourceDescription.prototype.getAnalysis = function(){
239
  return this.analysis;
240
};
241
242
/**
243
 * Set the analysis
244
 * 
245
 * @param {ResourceReference|Object} analysis
246
 * @return {SourceDescription}
247
 */
248
SourceDescription.prototype.setAnalysis = function(analysis){
249
  if(analysis){
250
    this.analysis = GedcomX.ResourceReference(analysis);
251
  }
252
  return this;
253
};
254
255
/**
256
 * Get the componentOf property
257
 * 
258
 * @return {SourceReference}
259
 */
260
SourceDescription.prototype.getComponentOf = function(){
261
  return this.componentOf;
262
};
263
264
/**
265
 * Set the componentOf property
266
 * 
267
 * @param {SourceReference} componentOf
268
 */
269
SourceDescription.prototype.setComponentOf = function(componentOf){
270
  if(componentOf){
271
    this.componentOf = GedcomX.SourceReference(componentOf);
272
  }
273
  return this;
274
};
275
276
/**
277
 * Get titles
278
 * 
279
 * @returns {TextValue[]}
280
 */
281
SourceDescription.prototype.getTitles = function(){
282
  return this.titles || [];
283
};
284
285
/**
286
 * Set the titles
287
 * 
288
 * @param {TextValue[]|Object[]} titles
289
 * @returns {SourceDescription}
290
 */
291
SourceDescription.prototype.setTitles = function(titles){
292
  return this._setArray(titles, 'titles', 'addTitle');
293
};
294
295
/**
296
 * Add a title
297
 * 
298
 * @param {TextValue|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
299
 * @returns {SourceDescription}
300
 */
301
SourceDescription.prototype.addTitle = function(title){
302
  return this._arrayPush(title, 'titles', GedcomX.TextValue);
303
};
304
305
/**
306
 * Get notes
307
 * 
308
 * @returns {Note[]}
309
 */
310
SourceDescription.prototype.getNotes = function(){
311
  return this.notes || [];
312
};
313
314
/**
315
 * Set the notes
316
 * 
317
 * @param {Note[]|Object[]} notes
318
 * @returns {SourceDescription}
319
 */
320
SourceDescription.prototype.setNotes = function(notes){
321
  return this._setArray(notes, 'notes', 'addNote');
322
};
323
324
/**
325
 * Add a source
326
 * 
327
 * @param {Note|Object} note
328
 * @returns {SourceDescription}
329
 */
330
SourceDescription.prototype.addNote = function(note){
331
  return this._arrayPush(note, 'notes', GedcomX.Note);
332
};
333
334
/**
335
 * Get the attribution
336
 * 
337
 * @returns {Attribution}
338
 */
339
SourceDescription.prototype.getAttribution = function(){
340
  return this.attribution;
341
};
342
343
/**
344
 * Set the attribution
345
 * 
346
 * @param {Attribution|Object} attribution
347
 * @returns {SourceDescription}
348
 */
349
SourceDescription.prototype.setAttribution = function(attribution){
350
  if(attribution){
351
    this.attribution = GedcomX.Attribution(attribution);
352
  }
353
  return this;
354
};
355
356
/**
357
 * Get the rights
358
 * 
359
 * @returns {ResourceReference[]}
360
 */
361
SourceDescription.prototype.getRights = function(){
362
  return this.rights || [];
363
};
364
365
/**
366
 * Set the rights
367
 * 
368
 * @param {ResourceReference[]|Object[]} rights
369
 * @returns {SourceDescription}
370
 */
371
SourceDescription.prototype.setRights = function(rights){
372
  return this._setArray(rights, 'rights', 'addRight');
373
};
374
375
/**
376
 * Add a source
377
 * 
378
 * @param {ResourceReference|Object} right
379
 * @returns {SourceDescription}
380
 */
381
SourceDescription.prototype.addRight = function(right){
382
  return this._arrayPush(right, 'rights', GedcomX.ResourceReference);
383
};
384
385
/**
386
 * Get the coverage
387
 * 
388
 * @returns {Coverage}
389
 */
390
SourceDescription.prototype.getCoverage = function(){
391
  return this.coverage || [];
392
};
393
394
/**
395
 * Set the coverage
396
 * 
397
 * @param {Coverage[]|Object[]} coverage
398
 * @returns {SourceDescription}
399
 */
400
SourceDescription.prototype.setCoverage = function(coverage){
401
  return this._setArray(coverage, 'coverage', 'addCoverage');
402
};
403
404
/**
405
 * Add coverage
406
 * 
407
 * @param {Coverage}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
408
 * @returns {SourceDescription}
409
 */
410
SourceDescription.prototype.addCoverage = function(coverage){
411
  return this._arrayPush(coverage, 'coverage', GedcomX.Coverage);
412
};
413
414
/**
415
 * Get the descriptions
416
 * 
417
 * @returns {TextValue[]}
418
 */
419
SourceDescription.prototype.getDescriptions = function(){
420
  return this.descriptions || [];
421
};
422
423
/**
424
 * Set the descriptions
425
 * 
426
 * @param {TextValue[]|Object[]} descriptions
427
 * @returns {SourceDescription}
428
 */
429
SourceDescription.prototype.setDescriptions = function(descriptions){
430
  return this._setArray(descriptions, 'descriptions', 'addDescription');
431
};
432
433
/**
434
 * Add a description
435
 * 
436
 * @param {TextValue|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
437
 * @returns {SourceDescription}
438
 */
439
SourceDescription.prototype.addDescription = function(description){
440
  return this._arrayPush(description, 'descriptions', GedcomX.TextValue);
441
};
442
443
/**
444
 * Get the identifiers
445
 * 
446
 * @returns {Identifiers}
447
 */
448
SourceDescription.prototype.getIdentifiers = function(){
449
  return this.identifiers;
450
};
451
452
/**
453
 * Set the identifiers
454
 * 
455
 * @param {Identifiers} identifiers
456
 * @returns {SourceDescription}
457
 */
458
SourceDescription.prototype.setIdentifiers = function(identifiers){
459
  if(identifiers){
460
    this.identifiers = GedcomX.Identifiers(identifiers);
461
  }
462
  return this;
463
};
464
465
/**
466
 * Get the created timestamp
467
 * 
468
 * @returns {Integer}
469
 */
470
SourceDescription.prototype.getCreated = function(){
471
  return this.created;
472
};
473
474
/**
475
 * Set the created timestamp
476
 * 
477
 * @param {Integer} created
478
 * @returns {SourceDescription}
479
 */
480
SourceDescription.prototype.setCreated = function(created){
481
  this.created = created;
482
  return this;
483
};
484
485
/**
486
 * Get the modified timestamp
487
 * 
488
 * @returns {Integer}
489
 */
490
SourceDescription.prototype.getModified = function(){
491
  return this.modified;
492
};
493
494
/**
495
 * Set the modified timestamp
496
 * 
497
 * @param {Integer} modified
498
 * @returns {SourceDescription}
499
 */
500
SourceDescription.prototype.setModified = function(modified){
501
  this.modified = modified;
502
  return this;
503
};
504
505
/**
506
 * Get the repository
507
 * 
508
 * @returns {ResourceReference}
509
 */
510
SourceDescription.prototype.getRepository = function(){
511
  return this.repository;
512
};
513
514
/**
515
 * Set the repository
516
 * 
517
 * @param {ResourceReference} repository
518
 * @returns {SourceDescription}
519
 */
520
SourceDescription.prototype.setRepository = function(repository){
521
  if(repository){
522
    this.repository = GedcomX.ResourceReference(repository);
523
  }
524
  return this;
525
};
526
527
/**
528
 * Export the object as JSON
529
 * 
530
 * @return {Object} JSON object
531
 */
532
SourceDescription.prototype.toJSON = function(){
533
  return this._toJSON(GedcomX.ExtensibleData, SourceDescription.jsonProps);
534
};
535
536
module.exports = SourceDescription;