| @@ 1-103 (lines=103) @@ | ||
| 1 | var ExtensibleData = require('./ExtensibleData'), |
|
| 2 | utils = require('./utils'); |
|
| 3 | ||
| 4 | /** |
|
| 5 | * A source citation. |
|
| 6 | * |
|
| 7 | * @constructor |
|
| 8 | * @apram {Object} [json] |
|
| 9 | */ |
|
| 10 | var SourceCitation = function(json){ |
|
| 11 | ||
| 12 | // Protect against forgetting the new keyword when calling the constructor |
|
| 13 | if(!(this instanceof SourceCitation)){ |
|
| 14 | return new SourceCitation(json); |
|
| 15 | } |
|
| 16 | ||
| 17 | // If the given object is already an instance then just return it. DON'T copy it. |
|
| 18 | if(SourceCitation.isInstance(json)){ |
|
| 19 | return json; |
|
| 20 | } |
|
| 21 | ||
| 22 | ExtensibleData.call(this, json); |
|
| 23 | ||
| 24 | if(json){ |
|
| 25 | this.setLang(json.lang); |
|
| 26 | this.setValue(json.value); |
|
| 27 | } |
|
| 28 | }; |
|
| 29 | ||
| 30 | SourceCitation.prototype = Object.create(ExtensibleData.prototype); |
|
| 31 | ||
| 32 | SourceCitation._gedxClass = SourceCitation.prototype._gedxClass = 'GedcomX.SourceCitation'; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Check whether the given object is an instance of this class. |
|
| 36 | * |
|
| 37 | * @param {Object} obj |
|
| 38 | * @returns {Boolean} |
|
| 39 | */ |
|
| 40 | SourceCitation.isInstance = function(obj){ |
|
| 41 | return utils.isInstance(obj, this._gedxClass); |
|
| 42 | }; |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Get the lang |
|
| 46 | * |
|
| 47 | * @returns {String} lang |
|
| 48 | */ |
|
| 49 | SourceCitation.prototype.getLang = function(){ |
|
| 50 | return this.lang; |
|
| 51 | }; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Set the lang |
|
| 55 | * |
|
| 56 | * @param {String} lang |
|
| 57 | * @returns {SourceCitation} This instance |
|
| 58 | */ |
|
| 59 | SourceCitation.prototype.setLang = function(lang){ |
|
| 60 | this.lang = lang; |
|
| 61 | return this; |
|
| 62 | }; |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Get the value |
|
| 66 | * |
|
| 67 | * @returns {String} value |
|
| 68 | */ |
|
| 69 | SourceCitation.prototype.getValue = function(){ |
|
| 70 | return this.value; |
|
| 71 | }; |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Set the value |
|
| 75 | * |
|
| 76 | * @param {String} value |
|
| 77 | * @returns {SourceCitation} This instance |
|
| 78 | */ |
|
| 79 | SourceCitation.prototype.setValue = function(value){ |
|
| 80 | this.value = value; |
|
| 81 | return this; |
|
| 82 | }; |
|
| 83 | ||
| 84 | /** |
|
| 85 | * Export the object as JSON |
|
| 86 | * |
|
| 87 | * @return {Object} JSON object |
|
| 88 | */ |
|
| 89 | SourceCitation.prototype.toJSON = function(){ |
|
| 90 | var json = ExtensibleData.prototype.toJSON.call(this); |
|
| 91 | ||
| 92 | if(this.lang){ |
|
| 93 | json.lang = this.lang; |
|
| 94 | } |
|
| 95 | ||
| 96 | if(this.value){ |
|
| 97 | json.value = this.value; |
|
| 98 | } |
|
| 99 | ||
| 100 | return json; |
|
| 101 | }; |
|
| 102 | ||
| 103 | module.exports = SourceCitation; |
|
| @@ 1-98 (lines=98) @@ | ||
| 1 | var utils = require('./utils'); |
|
| 2 | ||
| 3 | /** |
|
| 4 | * A text value in a specific language. |
|
| 5 | * |
|
| 6 | * @constructor |
|
| 7 | * @apram {Object} [json] |
|
| 8 | */ |
|
| 9 | var TextValue = function(json){ |
|
| 10 | ||
| 11 | // Protect against forgetting the new keyword when calling the constructor |
|
| 12 | if(!(this instanceof TextValue)){ |
|
| 13 | return new TextValue(json); |
|
| 14 | } |
|
| 15 | ||
| 16 | // If the given object is already an instance then just return it. DON'T copy it. |
|
| 17 | if(TextValue.isInstance(json)){ |
|
| 18 | return json; |
|
| 19 | } |
|
| 20 | ||
| 21 | if(json){ |
|
| 22 | this.setLang(json.lang); |
|
| 23 | this.setValue(json.value); |
|
| 24 | } |
|
| 25 | }; |
|
| 26 | ||
| 27 | TextValue._gedxClass = TextValue.prototype._gedxClass = 'GedcomX.TextValue'; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Check whether the given object is an instance of this class. |
|
| 31 | * |
|
| 32 | * @param {Object} obj |
|
| 33 | * @returns {Boolean} |
|
| 34 | */ |
|
| 35 | TextValue.isInstance = function(obj){ |
|
| 36 | return utils.isInstance(obj, this._gedxClass); |
|
| 37 | }; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Get the lang |
|
| 41 | * |
|
| 42 | * @returns {String} lang |
|
| 43 | */ |
|
| 44 | TextValue.prototype.getLang = function(){ |
|
| 45 | return this.lang; |
|
| 46 | }; |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Set the lang |
|
| 50 | * |
|
| 51 | * @param {String} lang |
|
| 52 | * @returns {TextValue} This instance |
|
| 53 | */ |
|
| 54 | TextValue.prototype.setLang = function(lang){ |
|
| 55 | this.lang = lang; |
|
| 56 | return this; |
|
| 57 | }; |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Get the value |
|
| 61 | * |
|
| 62 | * @returns {String} value |
|
| 63 | */ |
|
| 64 | TextValue.prototype.getValue = function(){ |
|
| 65 | return this.value; |
|
| 66 | }; |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Set the value |
|
| 70 | * |
|
| 71 | * @param {String} value |
|
| 72 | * @returns {TextValue} This instance |
|
| 73 | */ |
|
| 74 | TextValue.prototype.setValue = function(value){ |
|
| 75 | this.value = value; |
|
| 76 | return this; |
|
| 77 | }; |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Export the object as JSON |
|
| 81 | * |
|
| 82 | * @return {Object} JSON object |
|
| 83 | */ |
|
| 84 | TextValue.prototype.toJSON = function(){ |
|
| 85 | var json = {}; |
|
| 86 | ||
| 87 | if(this.lang){ |
|
| 88 | json.lang = this.lang; |
|
| 89 | } |
|
| 90 | ||
| 91 | if(this.value){ |
|
| 92 | json.value = this.value; |
|
| 93 | } |
|
| 94 | ||
| 95 | return json; |
|
| 96 | }; |
|
| 97 | ||
| 98 | module.exports = TextValue; |
|