From c3ec3f28bd1d8fe8abe403ee1e8ec974966e60ed Mon Sep 17 00:00:00 2001 From: hacksalot Date: Sun, 3 Jan 2016 05:03:31 -0500 Subject: [PATCH] Introduce section totals inspector. --- package.json | 1 + src/index.js | 1 + src/inspectors/totals-inspector.js | 66 ++++++++++++++++++++++++++++++ src/verbs/analyze.js | 16 +++++++- 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/inspectors/totals-inspector.js diff --git a/package.json b/package.json index eab3a21..e57dbf7 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "phantom": "^0.8.4", "recursive-readdir-sync": "^1.0.6", "simple-html-tokenizer": "^0.2.0", + "string-padding": "^1.0.2", "string.prototype.startswith": "^0.2.0", "underscore": "^1.8.3", "webshot": "^0.16.0", diff --git a/src/index.js b/src/index.js index 6a3d7c9..f6e603c 100644 --- a/src/index.js +++ b/src/index.js @@ -193,5 +193,6 @@ function splitSrcDest() { Simple logging placeholder. */ function logMsg( msg ) { + msg = msg || ''; opts.silent || console.log( msg ); } diff --git a/src/inspectors/totals-inspector.js b/src/inspectors/totals-inspector.js new file mode 100644 index 0000000..7efd94f --- /dev/null +++ b/src/inspectors/totals-inspector.js @@ -0,0 +1,66 @@ +/** +Totals analysis for HackMyResume. +@license MIT. See LICENSE.md for details. +@module gap-inspector.js +*/ + + + +(function() { + + + + var _ = require('underscore'); + var FluentDate = require('../core/fluent-date'); + + + + /** + Identify gaps in the candidate's employment history. + @class gapInspector + */ + var gapInspector = module.exports = { + + + + moniker: 'totals-inspector', + + /** + Run the Totals Analyzer on a resume. + @method run + @return An array of object representing gaps in the candidate's employment + history. Each object provides the start, end, and duration of the gap: + { <-- gap + start: // A Moment.js date + end: // A Moment.js date + duration: // Gap length + } + */ + run: function( rez ) { + + var ret = { }; + + _.each( rez, function(val, key){ + + if( _.isArray( val ) && !_.isString(val) ) { + ret[ key ] = val.length; + } + else if( val.history && _.isArray( val.history ) ) { + ret[ key ] = val.history.length; + } + else if( val.sets && _.isArray( val.sets ) ) { + ret[ key ] = val.sets.length; + } + + }); + + return ret; + + } + + + }; + + + +}()); diff --git a/src/verbs/analyze.js b/src/verbs/analyze.js index 48fbbc4..8954743 100644 --- a/src/verbs/analyze.js +++ b/src/verbs/analyze.js @@ -53,7 +53,20 @@ Implementation of the 'analyze' verb for HackMyResume. return val.run( resumeObject.rez ); }); - console.log('Gaps: ' + info.gaps.length ); + log(chalk.cyan('\nTotals: ')); + var pad = require('string-padding'); + _.each( info.totals, function(tot, key) { + log(chalk.cyan(pad(key + ': ',17)) + chalk.cyan.bold(pad(tot.toString(),4))); + }); + + log(); + log(chalk.cyan('Gaps: ') + chalk.cyan.bold(info.gaps.length) + + chalk.cyan(' [') + info.gaps.map(function(g) { + var clr = 'green'; + if( g.duration > 35 ) clr = 'yellow'; + if( g.duration > 90 ) clr = 'red'; + return chalk[clr].bold(g.duration); + }).join(', ') + chalk.cyan(']') ); } @@ -63,6 +76,7 @@ Implementation of the 'analyze' verb for HackMyResume. */ function _loadInspectors() { return { + totals: require('../inspectors/totals-inspector'), gaps: require('../inspectors/gap-inspector') }; }