Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

src/Conclusion.js   B

Complexity

Total Complexity 38
Complexity/F 1.81

Size

Lines of Code 259
Function Count 21

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 259
rs 8.3999
wmc 38
mnd 2
bc 38
fnc 21
bpm 1.8095
cpm 1.8095
noi 3

17 Functions

Rating   Name   Duplication   Size   Complexity  
A Conclusion.addNote 0 9 3
A Conclusion.getLang 0 3 1
A Conclusion.setAnalysis 0 6 2
A Conclusion.setNotes 0 10 2
A Conclusion.isInstance 0 3 1
C Conclusion.toJSON 0 33 7
A Conclusion.getSources 0 3 1
A Conclusion.getAnalysis 0 3 1
A Conclusion.setConfidence 0 4 1
A Conclusion.setAttribution 0 6 2
A Conclusion.addSource 0 9 3
A Conclusion.getConfidence 0 3 1
A Conclusion.setLang 0 4 1
A Conclusion.setSources 0 10 2
A Conclusion.getNotes 0 3 1
B Conclusion.js ➔ Conclusion 0 23 4
A Conclusion.getAttribution 0 3 1
1
var ExtensibleData = require('./ExtensibleData'),
2
    Attribution = require('./Attribution'),
3
    ResourceReference = require('./ResourceReference'),
4
    Note = require('./Note'),
5
    SourceReference = require('./SourceReference'),
6
    utils = require('./utils');
7
8
/**
9
 * An abstract concept for a basic genealogical data item.
10
 * 
11
 * @constructor
12
 * @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...
13
 */
14
var Conclusion = function(json){
15
  
16
  // Protect against forgetting the new keyword when calling the constructor
17
  if(!(this instanceof Conclusion)){
18
    return new Conclusion(json);
19
  }
20
  
21
  // If the given object is already an instance then just return it. DON'T copy it.
22
  if(Conclusion.isInstance(json)){
23
    return json;
24
  }
25
  
26
  ExtensibleData.call(this, json);
27
  
28
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
29
    this.setAttribution(json.attribution);
30
    this.setAnalysis(json.analysis);
31
    this.setConfidence(json.confidence);
32
    this.setLang(json.lang);
33
    this.setNotes(json.notes);
34
    this.setSources(json.sources);
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...
35
  }
36
};
37
38
Conclusion.prototype = Object.create(ExtensibleData.prototype);
39
40
Conclusion._gedxClass = Conclusion.prototype._gedxClass = 'GedcomX.Conclusion';
41
42
/**
43
 * Check whether the given object is an instance of this class.
44
 * 
45
 * @param {Object} obj
46
 * @returns {Boolean}
47
 */
48
Conclusion.isInstance = function(obj){
49
  return utils.isInstance(obj, this._gedxClass);
50
};
51
52
/**
53
 * Get the attribution.
54
 * 
55
 * @returns {Attribution}
56
 */
57
Conclusion.prototype.getAttribution = function(){
58
  return this.attribution;
59
};
60
61
/**
62
 * Set the attribution
63
 * 
64
 * @param {Object|Attribution} attribution
65
 * @returns {Conclusion} This instance
66
 */
67
Conclusion.prototype.setAttribution = function(attribution){
68
  if(attribution){
69
    this.attribution = new Attribution(attribution);
70
  }
71
  return this;
72
};
73
74
/**
75
 * Get analysis.
76
 * 
77
 * @returns {ResourceReference} analysis
78
 */
79
Conclusion.prototype.getAnalysis = function(){
80
  return this.analysis;
81
};
82
83
/**
84
 * Set the analysis
85
 * 
86
 * @param {Object|ResourceReference} analysis
87
 * @returns {Conclusion} This instance
88
 */
89
Conclusion.prototype.setAnalysis = function(analysis){
90
  if(analysis){
91
    this.analysis = new ResourceReference(analysis);
92
  }
93
  return this;
94
};
95
96
/**
97
 * Get the confidence.
98
 * 
99
 * @returns {String} confidence
100
 */
101
Conclusion.prototype.getConfidence = function(){
102
  return this.confidence;
103
};
104
105
/**
106
 * Set the confidence.
107
 * 
108
 * @param {String} confidence
109
 * @returns {Conclusion} This instance
110
 */
111
Conclusion.prototype.setConfidence = function(confidence){
112
  this.confidence = confidence;
113
  return this;
114
};
115
116
/**
117
 * Get the language identifier.
118
 * 
119
 * @returns {String} lang
120
 */
121
Conclusion.prototype.getLang = function(){
122
  return this.lang;
123
};
124
125
/**
126
 * Set the language identifier.
127
 * 
128
 * @param {String} lang
129
 * @returns {Conclusion} This instance.
130
 */
131
Conclusion.prototype.setLang = function(lang){
132
  this.lang = lang;
133
  return this;
134
};
135
136
/**
137
 * Get the notes
138
 * 
139
 * @returns {Note[]} notes
140
 */
141
Conclusion.prototype.getNotes = function(){
142
  return this.notes || [];
143
};
144
145
/**
146
 * Set the notes
147
 * 
148
 * @param {Object[]|Note[]} notes
149
 * @returns {Conclusion} This instance
150
 */
151
Conclusion.prototype.setNotes = function(notes){
152
  if(notes){
153
    var conclusion = this;
154
    conclusion.notes = [];
155
    notes.forEach(function(note){
156
      conclusion.addNote(note);
157
    });
158
  }
159
  return this;
160
};
161
162
/**
163
 * Add a note
164
 * 
165
 * @param {Object|Note} note
166
 * @returns {Conclusion} This instance
167
 */
168
Conclusion.prototype.addNote = function(note){
169
  if(note){
170
    if(!Array.isArray(this.notes)){
171
      this.notes = [];
172
    }
173
    this.notes.push(new Note(note));
174
  }
175
  return this;
176
};
177
178
/**
179
 * Get the sources
180
 * 
181
 * @returns {SourceReference[]}
182
 */
183
Conclusion.prototype.getSources = function(){
184
  return this.sources || [];
185
};
186
187
/**
188
 * Set the sources
189
 * 
190
 * @param {Object[]|SourceReference[]} sources
191
 * @returns {Conclusion} This instance
192
 */
193
Conclusion.prototype.setSources = function(sources){
194
  if(sources){
195
    var conclusion = this;
196
    conclusion.sources = [];
197
    sources.forEach(function(source){
198
      conclusion.addSource(source);
199
    });
200
  }
201
  return this;
202
};
203
204
/**
205
 * Add a source
206
 * 
207
 * @param {SourceReference} source
208
 * @returns {Conclusion} This instance
209
 */
210
Conclusion.prototype.addSource = function(source){
211
  if(source){
212
    if(!Array.isArray(this.sources)){
213
      this.sources = [];
214
    }
215
    this.sources.push(new SourceReference(source));
216
  }
217
  return this;
218
};
219
220
/**
221
 * Export the object as JSON
222
 * 
223
 * @return {Object} JSON object
224
 */
225
Conclusion.prototype.toJSON = function(){
226
  var json = ExtensibleData.prototype.toJSON.call(this);
227
  
228
  if(this.lang){
229
    json.lang = this.lang;
230
  }
231
  
232
  if(this.confidence){
233
    json.confidence = this.confidence;
234
  }
235
  
236
  if(this.analysis){
237
    json.analysis = this.analysis.toJSON();
238
  }
239
  
240
  if(this.attribution){
241
    json.attribution = this.attribution.toJSON();
242
  }
243
  
244
  if(this.sources){
245
    json.sources = this.sources.map(function(source){
246
      return source.toJSON();
247
    });
248
  }
249
  
250
  if(this.notes){
251
    json.notes = this.notes.map(function(note){
252
      return note.toJSON();
253
    });
254
  }
255
  
256
  return json;
257
};
258
259
module.exports = Conclusion;