2016-01-30 21:40:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Definition of the AbstractResume class.
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
@module core/abstract-resume
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var AbstractResume, FluentDate, _, __;
|
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
__ = require('lodash');
|
|
|
|
|
|
|
|
FluentDate = require('./fluent-date');
|
|
|
|
|
|
|
|
AbstractResume = (function() {
|
|
|
|
function AbstractResume() {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Compute the total duration of the work history.
|
|
|
|
@returns The total duration of the sheet's work history, that is, the number
|
|
|
|
of years between the start date of the earliest job on the resume and the
|
|
|
|
*latest end date of all jobs in the work history*. This last condition is for
|
|
|
|
sheets that have overlapping jobs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
AbstractResume.prototype.duration = function(collKey, startKey, endKey, unit) {
|
|
|
|
var firstDate, hist, lastDate, new_e;
|
|
|
|
unit = unit || 'years';
|
2016-01-31 01:06:04 +00:00
|
|
|
hist = __.get(this, collKey);
|
2016-01-30 21:40:22 +00:00
|
|
|
if (!hist || !hist.length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new_e = hist.map(function(job) {
|
|
|
|
var obj;
|
|
|
|
obj = _.pick(job, [startKey, endKey]);
|
|
|
|
if (!_.has(obj, endKey)) {
|
|
|
|
obj[endKey] = 'current';
|
|
|
|
}
|
|
|
|
if (obj && (obj[startKey] || obj[endKey])) {
|
|
|
|
obj = _.pairs(obj);
|
|
|
|
obj[0][1] = FluentDate.fmt(obj[0][1]);
|
|
|
|
if (obj.length > 1) {
|
|
|
|
obj[1][1] = FluentDate.fmt(obj[1][1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
});
|
|
|
|
new_e = _.filter(_.flatten(new_e, true), function(v) {
|
|
|
|
return v && v.length && v[0] && v[0].length;
|
|
|
|
});
|
|
|
|
if (!new_e || !new_e.length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new_e = _.sortBy(new_e, function(elem) {
|
|
|
|
return elem[1].unix();
|
|
|
|
});
|
|
|
|
firstDate = _.first(new_e)[1];
|
|
|
|
lastDate = _.last(new_e)[1];
|
|
|
|
return lastDate.diff(firstDate, unit);
|
|
|
|
};
|
|
|
|
|
2016-02-15 21:38:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Removes ignored or private fields from a resume object
|
|
|
|
@returns an object with the following structure:
|
|
|
|
{
|
|
|
|
scrubbed: the processed resume object
|
|
|
|
ignoreList: an array of ignored nodes that were removed
|
|
|
|
privateList: an array of private nodes that were removed
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
AbstractResume.prototype.scrubResume = function(rep, opts) {
|
|
|
|
var ignoreList, includePrivates, privateList, scrubbed, traverse;
|
|
|
|
traverse = require('traverse');
|
|
|
|
ignoreList = [];
|
|
|
|
privateList = [];
|
2018-02-01 11:44:07 +00:00
|
|
|
includePrivates = opts && opts["private"];
|
2018-01-31 20:22:15 +00:00
|
|
|
scrubbed = traverse(rep).map(function() {
|
2016-02-15 21:38:01 +00:00
|
|
|
if (!this.isLeaf) {
|
|
|
|
if (this.node.ignore === true || this.node.ignore === 'true') {
|
|
|
|
ignoreList.push(this.node);
|
2018-01-31 05:10:37 +00:00
|
|
|
this["delete"]();
|
2016-02-15 21:38:01 +00:00
|
|
|
} else if ((this.node["private"] === true || this.node["private"] === 'true') && !includePrivates) {
|
|
|
|
privateList.push(this.node);
|
2018-01-31 05:10:37 +00:00
|
|
|
this["delete"]();
|
2016-02-15 21:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 20:22:15 +00:00
|
|
|
if (_.isArray(this.node)) {
|
|
|
|
this.after(function() {
|
|
|
|
this.update(_.compact(this.node));
|
|
|
|
});
|
|
|
|
}
|
2016-02-15 21:38:01 +00:00
|
|
|
});
|
|
|
|
return {
|
|
|
|
scrubbed: scrubbed,
|
|
|
|
ingoreList: ignoreList,
|
|
|
|
privateList: privateList
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-01-30 21:40:22 +00:00
|
|
|
return AbstractResume;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
module.exports = AbstractResume;
|
|
|
|
|
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=abstract-resume.js.map
|