diff --git a/lib/profile.js b/lib/profile.js index cdd80bd..a017094 100644 --- a/lib/profile.js +++ b/lib/profile.js @@ -2,7 +2,7 @@ var companyFactory = require('./company'), experienceFactory = require('./experience'), //Honors = require('./honors'), - //Project = require('./projects'), + projectFactory = require('./projects'), educationFactory = require('./education'), languageFactory = require('./language'); @@ -25,7 +25,7 @@ module.exports = function(window) { websites: [], positions: [], //honors: [], - //projects: [], + projects: [], educations: [], skills: [], languages: [] @@ -49,13 +49,10 @@ module.exports = function(window) { // )); //}); // - //$('#background-projects div div').each(function () { - // profile.projects.push(new Project($(this).find('hgroup h4 a span:first').text(), - // $(this).find('> span.projects-date').text(), - // $(this).find('> p').text(), - // $(this).find('hgroup h4 a[href]').attr('href') - // )); - //}); + + $('#projects .project').each(function () { + profile.projects.push(projectFactory($(this))); + }); $('#education .schools .school').each(function () { profile.educations.push(educationFactory($(this))); diff --git a/lib/projects.js b/lib/projects.js index 0e3a2e8..0c0e1dc 100644 --- a/lib/projects.js +++ b/lib/projects.js @@ -1,17 +1,25 @@ -function Project(name, dates, description, projectlink) { - this.name = name; - this.dates = (function (dates) { - var dd = (~dates.indexOf('(') ? dates.substring(0, dates.indexOf('(')) : dates).split('–'), - current = dd[1] && ~dd[1].indexOf('Present') ? true : false; +'use strict'; - return { - start: dd[0] ? new Date(dd[0]).toJSON() : undefined, - end: dd[1] && !current ? new Date(dd[1]).toJSON() : undefined, - current: current - }; - })(dates); - this.description = description; - this.projectlink = projectlink; -} - -module.exports = Project; +module.exports = function (project) { + return { + name: project.find('.item-title a').text(), + dates: (function (dates) { + var dd = dates.map(function(idx) { + if (typeof idx === 'number') { + return dates[idx].innerHTML.trim(); + } else { + return undefined; + } + }); + var current = !dd[1] || ~dd[1].toLowerCase().indexOf('present') ? true : false; + return { + start: dd[0] ? new Date(dd[0]).toJSON() : undefined, + end: dd[1] && !current ? new Date(dd[1]).toJSON() : undefined, + current: current + }; + })(project.find('> span.projects-date time')), + description: project.find('.description').html(), + teamCount: project.find('.contributors .contributor').length, + projectlink: project.find('.item-title a[href]').attr('href') + }; +}; diff --git a/test/scraper-test.js b/test/scraper-test.js index 836ed46..df85bcc 100644 --- a/test/scraper-test.js +++ b/test/scraper-test.js @@ -10,18 +10,18 @@ describe('', function() { function validateProfile(profile) { should(profile).be.ok(); should(profile).have.property('name', 'Daniel Henrique Joppi'); - should(profile).have.property('headline', 'Software Architect na Rospo GeoTech'); - should(profile).have.property('location', 'Florianópolis, Santa Catarina, Brazil'); + should(profile).have.property('headline', 'Development Manager at Avalara'); + should(profile).have.property('location', 'Florianópolis Area, Brazil'); should(profile).have.property('summary').be.ok(); should(profile).have.property('industry').be.equal('Program Development'); should(profile).have.property('languages').length(5); - should(profile).have.property('skills').length(45); - should(profile).have.property('currentPositions').length(3); - should(profile).have.property('pastPositions').length(3); + should(profile).have.property('skills').length(49); + should(profile).have.property('currentPositions').length(0); + should(profile).have.property('pastPositions').length(0); should(profile).have.property('educations').length(1); - should(profile).have.property('positions').length(8); + should(profile).have.property('positions').length(10); //should(profile).have.property('honors').length(0); - //should(profile).have.property('projects').length(0); + should(profile).have.property('projects').length(0); should(profile).have.property('publicProfileUrl', url); }