Total Complexity | 9 |
Complexity/F | 1.8 |
Lines of Code | 78 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | var Conclusion = require('./Conclusion'), |
||
2 | utils = require('./utils'); |
||
3 | |||
4 | /** |
||
5 | * A gender conclusion. |
||
6 | * |
||
7 | * @constructor |
||
8 | * @param {Object} [json] |
||
|
|||
9 | */ |
||
10 | var Gender = function(json){ |
||
11 | |||
12 | // Protect against forgetting the new keyword when calling the constructor |
||
13 | if(!(this instanceof Gender)){ |
||
14 | return new Gender(json); |
||
15 | } |
||
16 | |||
17 | // If the given object is already an instance then just return it. DON'T copy it. |
||
18 | if(Gender.isInstance(json)){ |
||
19 | return json; |
||
20 | } |
||
21 | |||
22 | Conclusion.call(this, json); |
||
23 | |||
24 | if(json){ |
||
25 | this.setType(json.type); |
||
26 | } |
||
27 | }; |
||
28 | |||
29 | Gender.prototype = Object.create(Conclusion.prototype); |
||
30 | |||
31 | Gender._gedxClass = Gender.prototype._gedxClass = 'GedcomX.Gender'; |
||
32 | |||
33 | /** |
||
34 | * Check whether the given object is an instance of this class. |
||
35 | * |
||
36 | * @param {Object} obj |
||
37 | * @returns {Boolean} |
||
38 | */ |
||
39 | Gender.isInstance = function(obj){ |
||
40 | return utils.isInstance(obj, this._gedxClass); |
||
41 | }; |
||
42 | |||
43 | /** |
||
44 | * Get the gender type |
||
45 | * |
||
46 | * @returns {String} gender |
||
47 | */ |
||
48 | Gender.prototype.getType = function(){ |
||
49 | return this.type; |
||
50 | }; |
||
51 | |||
52 | /** |
||
53 | * Set the gender type |
||
54 | * |
||
55 | * @param {String} gender |
||
56 | * @returns {Gender} This instance |
||
57 | */ |
||
58 | Gender.prototype.setType = function(gender){ |
||
59 | this.type = gender; |
||
60 | return this; |
||
61 | }; |
||
62 | |||
63 | /** |
||
64 | * Export the object as JSON |
||
65 | * |
||
66 | * @return {Object} JSON object |
||
67 | */ |
||
68 | Gender.prototype.toJSON = function(){ |
||
69 | var json = Conclusion.prototype.toJSON.call(this); |
||
70 | |||
71 | if(this.type){ |
||
72 | json.type = this.type; |
||
73 | } |
||
74 | |||
75 | return json; |
||
76 | }; |
||
77 | |||
78 | module.exports = Gender; |