Skip to content

Commit

Permalink
Add Ordinance and Reservation; close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
justincy committed Nov 3, 2016
1 parent 66e75f2 commit f0db148
Show file tree
Hide file tree
Showing 6 changed files with 523 additions and 1 deletion.
146 changes: 146 additions & 0 deletions src/Ordinance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
module.exports = function(GedcomX){

/**
* LDS ordinance
*
* @class Ordinance
* @extends Reservation
* @param {Object} [json]
*/
var Ordinance = function(json){

// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Ordinance)){
return new Ordinance(json);
}

// If the given object is already an instance then just return it. DON'T copy it.
if(Ordinance.isInstance(json)){
return json;
}

this.init(json);
};

Ordinance.prototype = Object.create(GedcomX.Reservation.prototype);

Ordinance._gedxClass = Ordinance.prototype._gedxClass = 'GedcomX.Ordinance';

Ordinance.jsonProps = [
'living',
'date',
'templeCode'
];

/**
* Check whether the given object is an instance of this class.
*
* @memberof Ordinance
* @static
* @param {Object} obj
* @returns {Boolean}
*/
Ordinance.isInstance = function(obj){
return GedcomX.utils.isInstance(obj, this._gedxClass);
};

/**
* Initialize from JSON
*
* @memberof Ordinance
* @param {Object}
* @return Ordinance this
*/
Ordinance.prototype.init = function(json){

GedcomX.Reservation.prototype.init.call(this, json);

if(json){
this.setLiving(json.living);
this.setDate(json.date);
this.setTempleCode(json.templeCode);
}
return this;
};

/**
* Get the living flag
*
* @memberof Ordinance
* @returns {Boolean} living
*/
Ordinance.prototype.getLiving = function(){
return this.living;
};

/**
* Set the living
*
* @memberof Ordinance
* @param {Boolean} living
* @returns {Ordinance} this
*/
Ordinance.prototype.setLiving = function(living){
this.living = living;
return this;
};

/**
* Get the date
*
* @memberof Ordinance
* @returns {Date} date
*/
Ordinance.prototype.getDate = function(){
return this.date;
};

/**
* Set the date
*
* @memberof Ordinance
* @param {Date} date
* @returns {Ordinance} this
*/
Ordinance.prototype.setDate = function(date){
if(date){
this.date = GedcomX.Date(date);
}
return this;
};

/**
* Get the templeCode
*
* @memberof Ordinance
* @returns {String} templeCode
*/
Ordinance.prototype.getTempleCode = function(){
return this.templeCode;
};

/**
* Set the templeCode
*
* @memberof Ordinance
* @param {String} templeCode
* @returns {Ordinance} this
*/
Ordinance.prototype.setTempleCode = function(templeCode){
this.templeCode = templeCode;
return this;
};

/**
* Export the object as JSON
*
* @memberof Ordinance
* @return {Object} JSON object
*/
Ordinance.prototype.toJSON = function(){
return this._toJSON(GedcomX.Reservation, Ordinance.jsonProps);
};

GedcomX.Ordinance = Ordinance;

};
41 changes: 40 additions & 1 deletion src/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
module.exports = function(GedcomX){

// Extend serialization properties
GedcomX.Person.jsonProps.push('discussion-references');
GedcomX.Person.jsonProps.push('discussion-references', 'ordinances');

// Override init() so that we can deserialize normalized values
var oldInit = GedcomX.Person.prototype.init;
GedcomX.Person.prototype.init = function(json){
oldInit.call(this, json);
if(json){
this.setDiscussionReferences(json['discussion-references']);
this.setOrdinances(json.ordinances);
}
};

Expand Down Expand Up @@ -53,4 +54,42 @@ module.exports = function(GedcomX){
return this['discussion-references'] || [];
};

/**
* Set the ordinances
*
* @function setOrdinances
* @instance
* @memberof Person
* @param {Ordinance[]} ordinances
* @return {Person} this
*/
GedcomX.Person.prototype.setOrdinances = function(ordinances){
return this._setArray(ordinances, 'ordinances', 'addOrdinance');
};

/**
* Add an ordinance
*
* @function addOrdinance
* @instance
* @memberof Person
* @param {Ordinance} ordinance
* @return {Person} this
*/
GedcomX.Person.prototype.addOrdinance = function(ordinance){
return this._arrayPush(ordinance, 'ordinances', GedcomX.Ordinance);
};

/**
* Get the ordinances
*
* @function getOrdinances
* @instance
* @memberof Person
* @return {Ordinance[]} ordinances
*/
GedcomX.Person.prototype.getOrdinances = function(){
return this.ordinances || [];
};

};
Loading

0 comments on commit f0db148

Please sign in to comment.