Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ test:
@nodemon --exec "make test-once --quiet" --ext "coffee,js" --quiet

test-once:
@mocha ---require coffeescript/register --ext "coffee,js"
@mocha --require coffeescript/register --ext "coffee,js" 'test/**/*.coffee'

3 changes: 1 addition & 2 deletions src/coordinates.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Coordinates

extractCoordinateNumbers: (coordinates) ->
return coordinates.match(/-?\d+(\.\d+)?/g)



extractLatitude: ->
latitude = @coordinateNumbersToDecimal(@latitudeNumbers)
if @latitudeIsNegative()
Expand Down
11 changes: 8 additions & 3 deletions src/validator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class Validator


validate: (coordinates) ->
@checkContainsNoLetters(coordinates)
@checkValidOrientation(coordinates)
@checkNumbers(coordinates)
cleaned = @removeKnownStrings(coordinates)
@checkContainsNoLetters(cleaned)
@checkValidOrientation(cleaned)
@checkNumbers(cleaned)


checkContainsNoLetters: (coordinates) ->
Expand All @@ -21,6 +22,10 @@ class Validator
throw new Error('Coordinate contains invalid alphanumeric characters.')


removeKnownStrings: (coordinates) ->
coordinates.replace(/\bdeg\b/gi, '')


checkValidOrientation: (coordinates) ->
validOrientation = /^[^nsew]*[ns]?[^nsew]*[ew]?[^nsew]*$/i.test(coordinates)
if not validOrientation
Expand Down
6 changes: 6 additions & 0 deletions test/parser.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ expectation =
"40°25’6\"N 74°38’28\"W"
"40°25’6\" -74°38’28\""
"40d 25’ 6\" N 74d 38’ 28\" W"
"40 deg 25' 6\" N, 74 deg 38’ 28\" W"
"40 deg 25' 6\", -74 deg 38’ 28\""
"40.4183318N 74.6411133W"
"40° 25.0999, -74° 38.4668"
]
Expand Down Expand Up @@ -54,6 +56,8 @@ reversedExpectation =
"40°25’6\"S 74°38’28\"E"
"-40°25’6\" 74°38’28\""
"40d 25’ 6\" S 74d 38’ 28\" E"
"40 deg 25' 6\" S, 74 deg 38’ 28\" E"
"-40 deg 25' 6\", 74 deg 38’ 28\""
"40.4183318S 74.6411133E"
"40.4183318S 74.6411133"
"-40° 25.0999, 74° 38.4668"
Expand Down Expand Up @@ -81,6 +85,8 @@ invalidFormats = [
"40.1° W 60.1° W"
"40.1° N 60.1° N"
"-40.4183318, 12.345, 74.6411133"
"-40 degrees 25' 6\", 74 degrees 38’ 28\""
"-40 degN 25' 6\", 74 degW 38’ 28\""
]


Expand Down