Completed
Push — master ( e9f487...ea9df4 )
by Justin
01:38
created

module.exports   B

Complexity

Conditions 1
Paths 4

Size

Total Lines 92

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 92
rs 8.491

7 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 7 2
A 0 3 1
A 0 3 1
A 0 3 1
A 0 3 1
A 0 3 1
A 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * Records extensions to Root
3
 */
4
module.exports = function(GedcomX){
5
  
6
  // Extend serialization properties
7
  GedcomX.Root.jsonProps.push('recordDescriptors', 'collections');
8
  
9
  // Override init() so that we can deserialize normalized values
10
  var oldInit = GedcomX.Root.prototype.init;
11
  GedcomX.Root.prototype.init = function(json){
12
    oldInit.call(this, json);
13
    if(json){
14
      this.setRecordDescriptors(json.recordDescriptors);
15
      this.setCollections(json.collections);
16
    }
17
  };
18
  
19
  /**
20
   * Set the record descriptors
21
   * 
22
   * @function setRecordDescriptors
23
   * @instance
24
   * @memberof Root
25
   * @param {RecordDescriptor[]} recordDescriptors
26
   * @return {Root} this
27
   */
28
  GedcomX.Root.prototype.setRecordDescriptors = function(recordDescriptors){
29
    return this._setArray(recordDescriptors, 'recordDescriptors', 'addRecordDescriptor');
30
  };
31
  
32
  /**
33
   * Add a record descriptor
34
   * 
35
   * @function addRecordDescriptor
36
   * @instance
37
   * @memberof Root
38
   * @param {RecordDescriptor} recordDescriptor
39
   * @return {Root} this
40
   */
41
  GedcomX.Root.prototype.addRecordDescriptor = function(recordDescriptor){
42
    return this._arrayPush(recordDescriptor, 'recordDescriptors', GedcomX.RecordDescriptor);
43
  };
44
  
45
  /**
46
   * Get the recordDescriptors
47
   * 
48
   * @function getRecordDescriptors
49
   * @instance
50
   * @memberof Root
51
   * @return {Boolean} recordDescriptors
52
   */
53
  GedcomX.Root.prototype.getRecordDescriptors = function(){
54
    return this.recordDescriptors || [];
55
  };
56
  
57
  /**
58
   * Set the collections
59
   * 
60
   * @function setCollections
61
   * @instance
62
   * @memberof Root
63
   * @param {Collection[]} collections
64
   * @return {Root} this
65
   */
66
  GedcomX.Root.prototype.setCollections = function(collections){
67
    return this._setArray(collections, 'collections', 'addCollection');
68
  };
69
  
70
  /**
71
   * Add a collection
72
   * 
73
   * @function addCollection
74
   * @instance
75
   * @memberof Root
76
   * @param {Collection} collection
77
   * @return {Root} this
78
   */
79
  GedcomX.Root.prototype.addCollection = function(collection){
80
    return this._arrayPush(collection, 'collections', GedcomX.Collection);
81
  };
82
  
83
  /**
84
   * Get the collections
85
   * 
86
   * @function getCollections
87
   * @instance
88
   * @memberof Root
89
   * @return {Collection[]} collections
90
   */
91
  GedcomX.Root.prototype.getCollections = function(){
92
    return this.collections || [];
93
  };
94
  
95
};