Created
June 7, 2012 02:18
-
-
Save ryanbrubaker/2886116 to your computer and use it in GitHub Desktop.
Decoder model for morse code demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MorseDecoder extends Backbone.Model | |
initializeKey: => | |
""" | |
Omitting code that initializes the morse code key | |
dictionary. | |
""" | |
initialize: => | |
@inputTokens = [] | |
@numEmptyTokensInARow = 0 | |
@initializeKey() | |
processToken: (token) => | |
if token == '' | |
@parseTokens() if | |
++@numEmptyTokensInARow >= 10 | |
else if token == kWordStopToken | |
@parseTokens() if @inputTokens.length > 0 | |
@trigger('parsedCharacter', ' ') | |
else | |
@inputTokens.push(token) | |
@numEmptyTokensInARow = 0 | |
parseTokens: => | |
if @inputTokens.length > 0 | |
token = @key[@inputTokens.join('')] | |
@trigger('parsedCharacter', token) if | |
token != undefined | |
@numEmptyTokensInARow = 0 | |
@inputTokens.length = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment