Skip to content

Commit

Permalink
Initial street address parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
miksu committed Aug 21, 2015
1 parent 371f91e commit 362c43f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion UI/src/utils/LocationInputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
if (matchedCoordinates) {
return parseCoordinates(matchedCoordinates);
} else {
return null;
return parseStreet(input);
}
};

var parseCoordinates = function(coordinates) {
return { type: 'coordinate', lat: parseInt(coordinates[1], 10), lon: parseInt(coordinates[2], 10) };
};

var parseStreet = function(input) {
var result = _.map(input.split(','), _.trim);
return { type: 'street', street: result[0], municipality: result[1] };
};

var LocationInputParser = {
parse: parse
};
Expand Down
4 changes: 4 additions & 0 deletions UI/test/LocationInputParserSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ define(['chai', 'LocationInputParser'], function(chai, LocationInputParser) {
it('parses coordinate pairs', function() {
assert.deepEqual({ type: 'coordinate', lat: 123, lon: 345 }, LocationInputParser.parse('123,345'));
});

it('parses street addresses', function() {
assert.deepEqual({ type: 'street', street: 'Salorankatu 7', municipality: 'Salo' }, LocationInputParser.parse('Salorankatu 7, Salo'));
});
});

0 comments on commit 362c43f

Please sign in to comment.