HackMyResume/dist/verbs/analyze.js

100 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
(function() {
2018-02-12 05:05:29 +00:00
/**
Implementation of the 'analyze' verb for HackMyResume.
@module verbs/analyze
@license MIT. See LICENSE.md for details.
*/
/** Private workhorse for the 'analyze' command. */
/** Analyze a single resume. */
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, chalk;
2016-01-27 10:29:26 +00:00
MKDIRP = require('mkdirp');
PATH = require('path');
HMEVENT = require('../core/event-codes');
HMSTATUS = require('../core/status-codes');
_ = require('underscore');
ResumeFactory = require('../core/resume-factory');
Verb = require('../verbs/verb');
chalk = require('chalk');
2016-02-02 02:14:36 +00:00
/** An invokable resume analysis command. */
2018-02-12 05:05:29 +00:00
module.exports = AnalyzeVerb = class AnalyzeVerb extends Verb {
constructor() {
super('analyze', _analyze);
2016-01-27 10:29:26 +00:00
}
2018-02-12 05:05:29 +00:00
};
2016-01-27 10:29:26 +00:00
2016-02-02 02:14:36 +00:00
_analyze = function(sources, dst, opts) {
var nlzrs, results;
2016-01-27 10:29:26 +00:00
if (!sources || !sources.length) {
2016-02-02 02:14:36 +00:00
this.err(HMSTATUS.resumeNotFound, {
2016-01-27 10:29:26 +00:00
quit: true
2016-02-02 02:14:36 +00:00
});
return null;
2016-01-27 10:29:26 +00:00
}
nlzrs = _loadInspectors();
2016-02-02 02:14:36 +00:00
results = _.map(sources, function(src) {
var r;
r = ResumeFactory.loadOne(src, {
2016-01-27 10:29:26 +00:00
format: 'FRESH',
objectify: true,
inner: {
2018-02-12 05:05:29 +00:00
private: opts.private === true
}
2016-01-27 10:29:26 +00:00
}, this);
2016-02-02 02:14:36 +00:00
if (opts.assert && this.hasError()) {
return {};
}
if (r.fluenterror) {
r.quit = opts.assert;
this.err(r.fluenterror, r);
return r;
2016-01-27 10:29:26 +00:00
} else {
2016-02-02 02:14:36 +00:00
return _analyzeOne.call(this, r, nlzrs, opts);
2016-01-27 10:29:26 +00:00
}
}, this);
2016-02-02 02:14:36 +00:00
if (this.hasError() && !opts.assert) {
this.reject(this.errorCode);
} else if (!this.hasError()) {
this.resolve(results);
}
return results;
2016-01-27 10:29:26 +00:00
};
2016-02-02 02:14:36 +00:00
_analyzeOne = function(resumeObject, nlzrs, opts) {
2016-01-27 10:29:26 +00:00
var info, rez, safeFormat;
rez = resumeObject.rez;
safeFormat = rez.meta && rez.meta.format && rez.meta.format.startsWith('FRESH') ? 'FRESH' : 'JRS';
this.stat(HMEVENT.beforeAnalyze, {
fmt: safeFormat,
file: resumeObject.file
});
info = _.mapObject(nlzrs, function(val, key) {
return val.run(rez);
});
2016-02-02 02:14:36 +00:00
this.stat(HMEVENT.afterAnalyze, {
2016-01-27 10:29:26 +00:00
info: info
});
2016-02-02 02:14:36 +00:00
return info;
2016-01-27 10:29:26 +00:00
};
_loadInspectors = function() {
return {
totals: require('../inspectors/totals-inspector'),
coverage: require('../inspectors/gap-inspector'),
keywords: require('../inspectors/keyword-inspector')
};
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=analyze.js.map