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