Skip to content

Instantly share code, notes, and snippets.

@manveru
Created June 20, 2010 05:21
Show Gist options
  • Save manveru/445586 to your computer and use it in GitHub Desktop.
Save manveru/445586 to your computer and use it in GitHub Desktop.
Morse = Object clone
Morse translation-table = [
"A", ".-"
"B", "-..."
"C", "-.-."
"D", "-.."
"E", "."
"F", "..-."
"G", "--."
"H", "...."
"I", ".."
"J", ".---"
"K", "-.-"
"L", ".-.."
"M", "--"
"N", "-."
"O", "---"
"P", ".--."
"Q", "--.-"
"R", ".-."
"S", "..."
"T", "-"
"U", "..-"
"V", "...-"
"W", ".--"
"X", "-..-"
"Y", "-.--"
"Z", "--.."
"Ä", ".-.-"
"Á", ".--.-"
"Å", ".--.-"
"Ch", "----"
"É", "..-.."
"Ñ", "--.--"
"Ö", "---."
"Ü", "..--"
"0", "-----"
"1", ".----"
"2", "..---"
"3", "...--"
"4", "....-"
"5", "....."
"6", "-...."
"7", "--..."
"8", "---.."
"9", "----."
".", ".-.-.-"
",", "--..--"
":", "---..."
"?", "..--.."
"'", ".----."
"-", "-....-"
"/", "-..-."
"(", "-.--.-"
'"', ".-..-."
"@", ".--.-."
"=", "-...-"
] to-hash
Morse to-morse: = (string|
string map: [c|
(self translation-table at: (c uppercase)) + " "
] chop
)
Morse to-text: = (string|
((morse split) map: [m|
(self translation-table at-value: m)
]) join
)
test = "SOS"
morse = Morse to-morse: test
puts: morse
text = Morse to-text: morse
puts: text
# puts: (Morse to-morse: "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÁÅCÉÑÖÜ0123456789. ,:? '-/(@=")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment