1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 16:30:11 +00:00

Prep convert.js.

This commit is contained in:
hacksalot 2016-01-06 00:20:30 -05:00
parent c5eab0fd9c
commit 8203fa50ae

View File

@ -4,10 +4,16 @@ FRESH to JSON Resume conversion routiens.
@module convert.js @module convert.js
*/ */
(function(){
(function(){ // TODO: refactor everything
var _ = require('underscore'); var _ = require('underscore');
/** /**
Convert between FRESH and JRS resume/CV formats. Convert between FRESH and JRS resume/CV formats.
@class FRESHConverter @class FRESHConverter
@ -15,6 +21,7 @@ FRESH to JSON Resume conversion routiens.
var FRESHConverter = module.exports = { var FRESHConverter = module.exports = {
/** /**
Convert from JSON Resume format to FRESH. Convert from JSON Resume format to FRESH.
@method toFresh @method toFresh
@ -25,27 +32,21 @@ FRESH to JSON Resume conversion routiens.
foreign = (foreign === undefined || foreign === null) ? true : foreign; foreign = (foreign === undefined || foreign === null) ? true : foreign;
return { return {
name: src.basics.name, name: src.basics.name,
imp: src.basics.imp, imp: src.basics.imp,
info: { info: {
label: src.basics.label, label: src.basics.label,
class: src.basics.class, // <--> round-trip class: src.basics.class, // <--> round-trip
image: src.basics.picture, image: src.basics.picture,
brief: src.basics.summary brief: src.basics.summary
}, },
contact: { contact: {
email: src.basics.email, email: src.basics.email,
phone: src.basics.phone, phone: src.basics.phone,
website: src.basics.website, website: src.basics.website,
other: src.basics.other // <--> round-trip other: src.basics.other // <--> round-trip
}, },
meta: meta( true, src.meta ), meta: meta( true, src.meta ),
location: { location: {
city: src.basics.location.city, city: src.basics.location.city,
region: src.basics.location.region, region: src.basics.location.region,
@ -53,7 +54,6 @@ FRESH to JSON Resume conversion routiens.
code: src.basics.location.postalCode, code: src.basics.location.postalCode,
address: src.basics.location.address address: src.basics.location.address
}, },
employment: employment( src.work, true ), employment: employment( src.work, true ),
education: education( src.education, true), education: education( src.education, true),
service: service( src.volunteer, true), service: service( src.volunteer, true),
@ -68,6 +68,8 @@ FRESH to JSON Resume conversion routiens.
}; };
}, },
/** /**
Convert from FRESH format to JSON Resume. Convert from FRESH format to JSON Resume.
@param foreign True if non-JSON-Resume properties should be included in @param foreign True if non-JSON-Resume properties should be included in
@ -79,7 +81,6 @@ FRESH to JSON Resume conversion routiens.
foreign = (foreign === undefined || foreign === null) ? false : foreign; foreign = (foreign === undefined || foreign === null) ? false : foreign;
return { return {
basics: { basics: {
name: src.name, name: src.name,
label: src.info.label, label: src.info.label,
@ -99,7 +100,6 @@ FRESH to JSON Resume conversion routiens.
profiles: social( src.social, false ), profiles: social( src.social, false ),
imp: src.imp imp: src.imp
}, },
work: employment( src.employment, false ), work: employment( src.employment, false ),
education: education( src.education, false ), education: education( src.education, false ),
skills: skillsToJRS( src.skills, false ), skills: skillsToJRS( src.skills, false ),
@ -111,20 +111,21 @@ FRESH to JSON Resume conversion routiens.
samples: foreign ? src.samples : undefined, samples: foreign ? src.samples : undefined,
disposition: foreign ? src.disposition : undefined, disposition: foreign ? src.disposition : undefined,
languages: src.languages languages: src.languages
}; };
}, },
toSTRING: function( src ) { toSTRING: function( src ) {
function replacerJRS( key,value ) { // Exclude these keys from stringification function replacerJRS( key,value ) { // Exclude these keys
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result', 'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate',
'isModified', 'htmlPreview', 'display_progress_bar'], 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
function( val ) { return key.trim() === val; } function( val ) { return key.trim() === val; }
) ? undefined : value; ) ? undefined : value;
} }
function replacerFRESH( key,value ) { // Exclude these keys from stringification function replacerFRESH( key,value ) { // Exclude these keys
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'], 'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
function( val ) { return key.trim() === val; } function( val ) { return key.trim() === val; }
@ -136,6 +137,8 @@ FRESH to JSON Resume conversion routiens.
}; };
function meta( direction, obj ) { function meta( direction, obj ) {
//if( !obj ) return obj; // preserve null and undefined //if( !obj ) return obj; // preserve null and undefined
if( direction ) { if( direction ) {
@ -146,6 +149,8 @@ FRESH to JSON Resume conversion routiens.
return obj; return obj;
} }
function employment( obj, direction ) { function employment( obj, direction ) {
if( !obj ) return obj; if( !obj ) return obj;
if( !direction ) { if( !direction ) {
@ -170,7 +175,8 @@ FRESH to JSON Resume conversion routiens.
position: job.position, position: job.position,
employer: job.company, employer: job.company,
summary: job.summary, summary: job.summary,
current: (!job.endDate || !job.endDate.trim() || job.endDate.trim().toLowerCase() === 'current') || undefined, current: (!job.endDate || !job.endDate.trim() ||
job.endDate.trim().toLowerCase() === 'current') || undefined,
start: job.startDate, start: job.startDate,
end: job.endDate, end: job.endDate,
url: job.website, url: job.website,
@ -183,6 +189,7 @@ FRESH to JSON Resume conversion routiens.
} }
function education( obj, direction ) { function education( obj, direction ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -219,6 +226,8 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function service( obj, direction, foreign ) { function service( obj, direction, foreign ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -254,6 +263,8 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function social( obj, direction ) { function social( obj, direction ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -277,6 +288,8 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function recognition( obj, direction, foreign ) { function recognition( obj, direction, foreign ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -306,6 +319,8 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function references( obj, direction ) { function references( obj, direction ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -328,6 +343,8 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function writing( obj, direction ) { function writing( obj, direction ) {
if( !obj ) return obj; if( !obj ) return obj;
if( direction ) { if( direction ) {
@ -346,7 +363,8 @@ FRESH to JSON Resume conversion routiens.
return obj && obj.length ? obj.map(function(pub){ return obj && obj.length ? obj.map(function(pub){
return { return {
name: pub.title, name: pub.title,
publisher: pub.publisher && pub.publisher.name ? pub.publisher.name : pub.publisher, publisher: pub.publisher &&
pub.publisher.name ? pub.publisher.name : pub.publisher,
releaseDate: pub.date, releaseDate: pub.date,
website: pub.url, website: pub.url,
summary: pub.summary summary: pub.summary
@ -355,8 +373,10 @@ FRESH to JSON Resume conversion routiens.
} }
} }
function skillsToFRESH( skills ) {
function skillsToFRESH( skills ) {
if( !skills ) return skills;
return { return {
sets: skills.map(function( set ) { sets: skills.map(function( set ) {
return { return {
@ -368,7 +388,10 @@ FRESH to JSON Resume conversion routiens.
}; };
} }
function skillsToJRS( skills ) { function skillsToJRS( skills ) {
if( !skills ) return skills;
var ret = []; var ret = [];
if( skills.sets && skills.sets.length ) { if( skills.sets && skills.sets.length ) {
ret = skills.sets.map(function(set){ ret = skills.sets.map(function(set){