From d8b9d86896531f8276e23098d2210d2bf96d8aa0 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Fri, 1 Jan 2016 17:30:57 -0500 Subject: [PATCH] Scrub. --- src/verbs/convert.js | 51 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/src/verbs/convert.js b/src/verbs/convert.js index c70196d..2539c96 100644 --- a/src/verbs/convert.js +++ b/src/verbs/convert.js @@ -4,35 +4,58 @@ Implementation of the 'convert' verb for HackMyResume. @license MIT. See LICENSE.md for details. */ + + (function(){ - var ResumeFactory = require('../core/resume-factory'); - var chalk = require('chalk'); + + + var ResumeFactory = require('../core/resume-factory') + , chalk = require('chalk'); + + /** Convert between FRESH and JRS formats. */ module.exports = function convert( sources, dst, opts, logger ) { + + // Housekeeping var _log = logger || console.log; if( !sources || !sources.length ) { throw { fluenterror: 6 }; } if( !dst || !dst.length ) { if( sources.length === 1 ) { throw { fluenterror: 5 }; } - else if( sources.length === 2 ) { dst = [ sources[1] ]; sources = [ sources[0] ]; } + else if( sources.length === 2 ) { + dst = [ sources[1] ]; sources = [ sources[0] ]; + } else { throw { fluenterror: 5 }; } } - if( sources && dst && sources.length && dst.length && sources.length !== dst.length ) { - throw { fluenterror: 7 }; - } - var sourceResumes = ResumeFactory.load( sources, { log: _log, format: null, objectify: true, throw: true } ); + if( sources && dst && sources.length && dst.length && + sources.length !== dst.length ) { throw { fluenterror: 7 }; } + + // Load source resumes + var sourceResumes = ResumeFactory.load( sources, { + log: _log, format: null, objectify: true, throw: true + }); + + // Apply the conversion to each sourceResumes.forEach(function( src, idx ) { - var sheet = src.rez; - var sourceFormat = ((sheet.basics && sheet.basics.imp) || sheet.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH'; - var targetFormat = sourceFormat === 'JRS' ? 'FRESH' : 'JRS'; - _log( chalk.green('Converting ') + chalk.green.bold(src.file) + chalk.green(' (' + - sourceFormat + ') to ') + chalk.green.bold(dst[0]) + - chalk.green(' (' + targetFormat + ').') ); - sheet.saveAs( dst[idx], targetFormat ); + + var s = src.rez + , srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ? + 'JRS' : 'FRESH'; + + var targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS'; + + // TODO: Core should not log + _log( chalk.green('Converting ') + chalk.green.bold(src.file) + + chalk.green(' (' + sourceFormat + ') to ') + chalk.green.bold(dst[0]) + + chalk.green(' (' + targetFormat + ').')); + + s.saveAs( dst[idx], targetFormat ); }); }; + + }());