Skip to content

Commit

Permalink
Express relative distance between stations as decimal between 0 and 1…
Browse files Browse the repository at this point in the history
… (instead of 0% to 100%).
  • Loading branch information
pekim committed Aug 28, 2011
1 parent 1edc8b7 commit 2964cbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/location-text.coffee
Expand Up @@ -5,18 +5,18 @@ parse = (text) ->

switch verb
when 'At'
location.distancePercent = 0
location.relativeDistance = 0.0
location.station = /At\s+(.*)\s+Platform.*/.exec(text)[1]
when 'Left'
location.distancePercent = 25
location.relativeDistance = 0.25
location.station = /Left\s+(.*)\s*/.exec(text)[1]
when 'Between'
location.distancePercent = 50
location.relativeDistance = 0.5
stations = /Between\s+(.*?)\s+and\s+(.*)\s*/.exec(text)
location.station = stations[1]
location.station2 = stations[2]
when 'Approaching'
location.distancePercent = 75
location.relativeDistance = 0.75
else
location.station = text

Expand Down
8 changes: 4 additions & 4 deletions test/location-text-test.coffee
Expand Up @@ -4,15 +4,15 @@ exports.at = (test) ->
location = locationText.parse 'At Stepney Green Platform 1'

test.strictEqual 'Stepney Green', location.station
test.strictEqual 0, location.distancePercent
test.strictEqual 0, location.relativeDistance

test.done()

exports.left = (test) ->
location = locationText.parse 'Left Tower Hill'

test.strictEqual 'Tower Hill', location.station
test.strictEqual 25, location.distancePercent
test.strictEqual 0.25, location.relativeDistance

test.done()

Expand All @@ -21,7 +21,7 @@ exports.between = (test) ->

test.strictEqual 'Willesden Junction', location.station
test.strictEqual 'Kensal Green', location.station2
test.strictEqual 50, location.distancePercent
test.strictEqual 0.5, location.relativeDistance

test.done()

Expand All @@ -30,6 +30,6 @@ exports.betweenWithAnd = (test) ->

test.strictEqual 'Lambeth', location.station
test.strictEqual 'Elephant and Castle', location.station2
test.strictEqual 50, location.distancePercent
test.strictEqual 0.5, location.relativeDistance

test.done()

0 comments on commit 2964cbc

Please sign in to comment.