|
1
|
|
View Code Duplication |
var ExtensibleData = require('./ExtensibleData'), |
|
|
|
|
|
|
2
|
|
|
utils = require('./utils'); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* A source citation. |
|
6
|
|
|
* |
|
7
|
|
|
* @constructor |
|
8
|
|
|
* @apram {Object} [json] |
|
9
|
|
|
*/ |
|
10
|
|
|
var SourceCitation = function(json){ |
|
11
|
|
|
|
|
12
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
|
13
|
|
|
if(!(this instanceof SourceCitation)){ |
|
14
|
|
|
return new SourceCitation(json); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
|
18
|
|
|
if(SourceCitation.isInstance(json)){ |
|
19
|
|
|
return json; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
ExtensibleData.call(this, json); |
|
23
|
|
|
|
|
24
|
|
|
if(json){ |
|
|
|
|
|
|
25
|
|
|
this.setLang(json.lang); |
|
26
|
|
|
this.setValue(json.value); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
SourceCitation.prototype = Object.create(ExtensibleData.prototype); |
|
31
|
|
|
|
|
32
|
|
|
SourceCitation._gedxClass = SourceCitation.prototype._gedxClass = 'GedcomX.SourceCitation'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Check whether the given object is an instance of this class. |
|
36
|
|
|
* |
|
37
|
|
|
* @param {Object} obj |
|
38
|
|
|
* @returns {Boolean} |
|
39
|
|
|
*/ |
|
40
|
|
|
SourceCitation.isInstance = function(obj){ |
|
41
|
|
|
return utils.isInstance(obj, this._gedxClass); |
|
42
|
|
|
}; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the lang |
|
46
|
|
|
* |
|
47
|
|
|
* @returns {String} lang |
|
48
|
|
|
*/ |
|
49
|
|
|
SourceCitation.prototype.getLang = function(){ |
|
50
|
|
|
return this.lang; |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Set the lang |
|
55
|
|
|
* |
|
56
|
|
|
* @param {String} lang |
|
57
|
|
|
* @returns {SourceCitation} This instance |
|
58
|
|
|
*/ |
|
59
|
|
|
SourceCitation.prototype.setLang = function(lang){ |
|
60
|
|
|
this.lang = lang; |
|
61
|
|
|
return this; |
|
62
|
|
|
}; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the value |
|
66
|
|
|
* |
|
67
|
|
|
* @returns {String} value |
|
68
|
|
|
*/ |
|
69
|
|
|
SourceCitation.prototype.getValue = function(){ |
|
70
|
|
|
return this.value; |
|
71
|
|
|
}; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Set the value |
|
75
|
|
|
* |
|
76
|
|
|
* @param {String} value |
|
77
|
|
|
* @returns {SourceCitation} This instance |
|
78
|
|
|
*/ |
|
79
|
|
|
SourceCitation.prototype.setValue = function(value){ |
|
80
|
|
|
this.value = value; |
|
81
|
|
|
return this; |
|
82
|
|
|
}; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Export the object as JSON |
|
86
|
|
|
* |
|
87
|
|
|
* @return {Object} JSON object |
|
88
|
|
|
*/ |
|
89
|
|
|
SourceCitation.prototype.toJSON = function(){ |
|
90
|
|
|
var json = ExtensibleData.prototype.toJSON.call(this); |
|
91
|
|
|
|
|
92
|
|
|
if(this.lang){ |
|
93
|
|
|
json.lang = this.lang; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if(this.value){ |
|
97
|
|
|
json.value = this.value; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return json; |
|
101
|
|
|
}; |
|
102
|
|
|
|
|
103
|
|
|
module.exports = SourceCitation; |