| @@ 1-111 (lines=111) @@ | ||
| 1 | var GedcomX = require('../'), |
|
| 2 | utils = require('../utils'); |
|
| 3 | ||
| 4 | /** |
|
| 5 | * A date. |
|
| 6 | * |
|
| 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-date|GEDCOM X JSON Spec} |
|
| 8 | * |
|
| 9 | * @class |
|
| 10 | * @extends ExtensibleData |
|
| 11 | * @param {Object} [json] |
|
| 12 | * @alias Date |
|
| 13 | */ |
|
| 14 | var GDate = function(json){ |
|
| 15 | ||
| 16 | // Protect against forgetting the new keyword when calling the constructor |
|
| 17 | if(!(this instanceof GDate)){ |
|
| 18 | return new GDate(json); |
|
| 19 | } |
|
| 20 | ||
| 21 | // If the given object is already an instance then just return it. DON'T copy it. |
|
| 22 | if(GDate.isInstance(json)){ |
|
| 23 | return json; |
|
| 24 | } |
|
| 25 | ||
| 26 | this.init(json); |
|
| 27 | }; |
|
| 28 | ||
| 29 | GDate.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
|
| 30 | ||
| 31 | GDate._gedxClass = GDate.prototype._gedxClass = 'GedcomX.Date'; |
|
| 32 | ||
| 33 | GDate.jsonProps = [ |
|
| 34 | 'original', |
|
| 35 | 'formal' |
|
| 36 | ]; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Check whether the given object is an instance of this class. |
|
| 40 | * |
|
| 41 | * @param {Object} obj |
|
| 42 | * @returns {Boolean} |
|
| 43 | */ |
|
| 44 | GDate.isInstance = function(obj){ |
|
| 45 | return utils.isInstance(obj, this._gedxClass); |
|
| 46 | }; |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Initialize from JSON |
|
| 50 | * |
|
| 51 | * @param {Object} |
|
| 52 | * @return {Date} this |
|
| 53 | */ |
|
| 54 | GDate.prototype.init = function(json){ |
|
| 55 | ||
| 56 | GedcomX.ExtensibleData.prototype.init.call(this, json); |
|
| 57 | ||
| 58 | if(json){ |
|
| 59 | this.setOriginal(json.original); |
|
| 60 | this.setFormal(json.formal); |
|
| 61 | } |
|
| 62 | return this; |
|
| 63 | }; |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Get the original date value |
|
| 67 | * |
|
| 68 | * @returns {String} original |
|
| 69 | */ |
|
| 70 | GDate.prototype.getOriginal = function(){ |
|
| 71 | return this.original; |
|
| 72 | }; |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Set the original date value |
|
| 76 | * |
|
| 77 | * @param {String} original |
|
| 78 | * @returns {Date} This instance. |
|
| 79 | */ |
|
| 80 | GDate.prototype.setOriginal = function(original){ |
|
| 81 | this.original = original; |
|
| 82 | return this; |
|
| 83 | }; |
|
| 84 | ||
| 85 | /** |
|
| 86 | * Get the formal date value |
|
| 87 | * |
|
| 88 | * @returns {String} |
|
| 89 | */ |
|
| 90 | GDate.prototype.getFormal = function(){ |
|
| 91 | return this.formal; |
|
| 92 | }; |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Set the formal date value |
|
| 96 | * |
|
| 97 | * @param {String} formal |
|
| 98 | * @returns {Date} This instance. |
|
| 99 | */ |
|
| 100 | GDate.prototype.setFormal = function(formal){ |
|
| 101 | this.formal = formal; |
|
| 102 | return this; |
|
| 103 | }; |
|
| 104 | ||
| 105 | /** |
|
| 106 | * Export the object as JSON |
|
| 107 | * |
|
| 108 | * @return {Object} JSON object |
|
| 109 | */ |
|
| 110 | GDate.prototype.toJSON = function(){ |
|
| 111 | return this._toJSON(GedcomX.ExtensibleData, GDate.jsonProps); |
|
| 112 | }; |
|
| 113 | ||
| 114 | module.exports = GDate; |
|
| @@ 1-110 (lines=110) @@ | ||
| 1 | var GedcomX = require('../'), |
|
| 2 | utils = require('../utils'); |
|
| 3 | ||
| 4 | /** |
|
| 5 | * A reference to a {@link PlaceDescription}. |
|
| 6 | * |
|
| 7 | * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-place-reference|GEDCOM X JSON Spec} |
|
| 8 | * |
|
| 9 | * @class |
|
| 10 | * @extends ExtensibleData |
|
| 11 | * @param {Object} [json] |
|
| 12 | */ |
|
| 13 | var PlaceReference = function(json){ |
|
| 14 | ||
| 15 | // Protect against forgetting the new keyword when calling the constructor |
|
| 16 | if(!(this instanceof PlaceReference)){ |
|
| 17 | return new PlaceReference(json); |
|
| 18 | } |
|
| 19 | ||
| 20 | // If the given object is already an instance then just return it. DON'T copy it. |
|
| 21 | if(GedcomX.ExtensibleData.isInstance(json)){ |
|
| 22 | return json; |
|
| 23 | } |
|
| 24 | ||
| 25 | this.init(json); |
|
| 26 | }; |
|
| 27 | ||
| 28 | PlaceReference.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
|
| 29 | ||
| 30 | PlaceReference._gedxClass = PlaceReference.prototype._gedxClass = 'GedcomX.ExtensibleData'; |
|
| 31 | ||
| 32 | PlaceReference.jsonProps = [ |
|
| 33 | 'original', |
|
| 34 | 'description' |
|
| 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 | PlaceReference.isInstance = function(obj){ |
|
| 44 | return utils.isInstance(obj, this._gedxClass); |
|
| 45 | }; |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Initialize from JSON |
|
| 49 | * |
|
| 50 | * @param {Object} |
|
| 51 | * @return {PlaceReference} this |
|
| 52 | */ |
|
| 53 | PlaceReference.prototype.init = function(json){ |
|
| 54 | ||
| 55 | GedcomX.ExtensibleData.prototype.init.call(this, json); |
|
| 56 | ||
| 57 | if(json){ |
|
| 58 | this.setOriginal(json.original); |
|
| 59 | this.setDescription(json.description); |
|
| 60 | } |
|
| 61 | return this; |
|
| 62 | }; |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Get the original text |
|
| 66 | * |
|
| 67 | * @returns {String} original |
|
| 68 | */ |
|
| 69 | PlaceReference.prototype.getOriginal = function(){ |
|
| 70 | return this.original; |
|
| 71 | }; |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Set the original text |
|
| 75 | * |
|
| 76 | * @param {String} original |
|
| 77 | * @returns {PlaceReference} This instance. |
|
| 78 | */ |
|
| 79 | PlaceReference.prototype.setOriginal = function(original){ |
|
| 80 | this.original = original; |
|
| 81 | return this; |
|
| 82 | }; |
|
| 83 | ||
| 84 | /** |
|
| 85 | * Get the description |
|
| 86 | * |
|
| 87 | * @returns {String} |
|
| 88 | */ |
|
| 89 | PlaceReference.prototype.getDescription = function(){ |
|
| 90 | return this.description; |
|
| 91 | }; |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Set the description |
|
| 95 | * |
|
| 96 | * @param {String} description |
|
| 97 | * @returns {PlaceReference} This instance. |
|
| 98 | */ |
|
| 99 | PlaceReference.prototype.setDescription = function(description){ |
|
| 100 | this.description = description; |
|
| 101 | return this; |
|
| 102 | }; |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Export the object as JSON |
|
| 106 | * |
|
| 107 | * @return {Object} JSON object |
|
| 108 | */ |
|
| 109 | PlaceReference.prototype.toJSON = function(){ |
|
| 110 | return this._toJSON(GedcomX.ExtensibleData, PlaceReference.jsonProps); |
|
| 111 | }; |
|
| 112 | ||
| 113 | module.exports = PlaceReference; |
|