1
|
|
|
module.exports = function(GedcomX){ |
2
|
|
|
|
3
|
|
|
var utils = require('../utils'), |
4
|
|
|
AtomCommon = require('./AtomCommon'); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Common schema for atom authors and contributors. |
8
|
|
|
* |
9
|
|
|
* @constructor |
10
|
|
|
* @param {Object} [json] |
|
|
|
|
11
|
|
|
*/ |
12
|
|
|
var AtomPerson = function(json){ |
13
|
|
|
|
14
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
15
|
|
|
if(!(this instanceof AtomPerson)){ |
16
|
|
|
return new AtomPerson(json); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
20
|
|
|
if(AtomPerson.isInstance(json)){ |
21
|
|
|
return json; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
this.init(json); |
|
|
|
|
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
AtomPerson.prototype = Object.create(AtomCommon.prototype); |
28
|
|
|
|
29
|
|
|
AtomPerson._gedxClass = AtomPerson.prototype._gedxClass = 'GedcomX.AtomPerson'; |
30
|
|
|
|
31
|
|
|
AtomPerson.jsonProps = [ |
32
|
|
|
'uri', |
33
|
|
|
'name', |
34
|
|
|
'email' |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Check whether the given object is an instance of this class. |
39
|
|
|
* |
40
|
|
|
* @param {Object} obj |
41
|
|
|
* @returns {Boolean} |
42
|
|
|
*/ |
43
|
|
|
AtomPerson.isInstance = function(obj){ |
44
|
|
|
return utils.isInstance(obj, this._gedxClass); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize from JSON |
49
|
|
|
* |
50
|
|
|
* @param {Object} |
|
|
|
|
51
|
|
|
* @return {AtomPerson} this |
52
|
|
|
*/ |
53
|
|
|
AtomPerson.prototype.init = function(json){ |
54
|
|
|
|
55
|
|
|
AtomCommon.prototype.init.call(this, json); |
56
|
|
|
|
57
|
|
|
if(json){ |
58
|
|
|
this.setUri(json.uri); |
59
|
|
|
this.setName(json.name); |
60
|
|
|
this.setEmail(json.email); |
61
|
|
|
} |
62
|
|
|
return this; |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set the uri |
67
|
|
|
* |
68
|
|
|
* @param {String} uri |
69
|
|
|
* @return {AtomPerson} this |
70
|
|
|
*/ |
71
|
|
|
AtomPerson.prototype.setUri = function(uri){ |
72
|
|
|
this.uri = uri; |
73
|
|
|
return this; |
74
|
|
|
}; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the uri |
78
|
|
|
* |
79
|
|
|
* @return {String} this |
80
|
|
|
*/ |
81
|
|
|
AtomPerson.prototype.getUri = function(){ |
82
|
|
|
return this.uri; |
83
|
|
|
}; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Set the name |
87
|
|
|
* |
88
|
|
|
* @param {String} name |
89
|
|
|
* @return {AtomPerson} this |
90
|
|
|
*/ |
91
|
|
|
AtomPerson.prototype.setName = function(name){ |
92
|
|
|
this.name = name; |
93
|
|
|
return this; |
94
|
|
|
}; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get the name |
98
|
|
|
* |
99
|
|
|
* @return {String} this |
100
|
|
|
*/ |
101
|
|
|
AtomPerson.prototype.getName = function(){ |
102
|
|
|
return this.name; |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Set the email |
107
|
|
|
* |
108
|
|
|
* @param {String} email |
109
|
|
|
* @return {AtomPerson} this |
110
|
|
|
*/ |
111
|
|
|
AtomPerson.prototype.setEmail = function(email){ |
112
|
|
|
this.email = email; |
113
|
|
|
return this; |
114
|
|
|
}; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get the name |
118
|
|
|
* |
119
|
|
|
* @return {String} this |
120
|
|
|
*/ |
121
|
|
|
AtomPerson.prototype.getEmail = function(){ |
122
|
|
|
return this.email; |
123
|
|
|
}; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Export the object as JSON |
127
|
|
|
* |
128
|
|
|
* @return {Object} JSON object |
129
|
|
|
*/ |
130
|
|
|
AtomPerson.prototype.toJSON = function(){ |
131
|
|
|
return this._toJSON(AtomCommon, AtomPerson.jsonProps); |
132
|
|
|
}; |
133
|
|
|
|
134
|
|
|
GedcomX.AtomPerson = AtomPerson; |
135
|
|
|
|
136
|
|
|
}; |