Total Complexity | 7 |
Complexity/F | 2.33 |
Lines of Code | 54 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | var utils = require('./utils'); |
||
2 | |||
3 | /** |
||
4 | * Manage the set of identifers for an object. |
||
5 | * |
||
6 | * @constructor |
||
7 | * @param {Object} [json] |
||
|
|||
8 | */ |
||
9 | var Identifiers = function(json){ |
||
10 | |||
11 | // Protect against forgetting the new keyword when calling the constructor |
||
12 | if(!(this instanceof Identifiers)){ |
||
13 | return new Identifiers(json); |
||
14 | } |
||
15 | |||
16 | // If the given object is already an instance then just return it. DON'T copy it. |
||
17 | if(Identifiers.isInstance(json)){ |
||
18 | return json; |
||
19 | } |
||
20 | |||
21 | this.identifiers = {}; |
||
22 | |||
23 | if(json){ |
||
24 | if(json instanceof Identifiers){ |
||
25 | this.identifiers = json.identifiers; |
||
26 | } else { |
||
27 | this.identifiers = json; |
||
28 | } |
||
29 | } |
||
30 | }; |
||
31 | |||
32 | Identifiers._gedxClass = Identifiers.prototype._gedxClass = 'GedcomX.Identifiers'; |
||
33 | |||
34 | /** |
||
35 | * Check whether the given object is an instance of this class. |
||
36 | * |
||
37 | * @param {Object} obj |
||
38 | * @returns {Boolean} |
||
39 | */ |
||
40 | Identifiers.isInstance = function(obj){ |
||
41 | return utils.isInstance(obj, this._gedxClass); |
||
42 | }; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * Export the object as JSON |
||
47 | * |
||
48 | * @return {Object} JSON object |
||
49 | */ |
||
50 | Identifiers.prototype.toJSON = function(){ |
||
51 | return this.identifiers; |
||
52 | }; |
||
53 | |||
54 | module.exports = Identifiers; |