Created
December 15, 2012 00:23
-
-
Save Solnse/4289914 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def translate(word) | |
word_list = word.split(/ /) | |
letters = ('a'..'z').to_a | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
consonants = letters - vowels | |
result = "" | |
word_list.each do |word| | |
if vowels.include?(word[0]) #translate word beginning with vowels. | |
result << word + "ay" | |
elsif consonants.include?(word[0]) | |
if consonants.include?(word[1]) | |
if consonants.include?(word[2]) #word begins with 3 consonants. | |
result << word[3..-1] + word[0..2] + "ay" | |
else #word begins with 2 consonants. | |
result << word[2..-1] + word[0..1] + "ay" | |
end | |
elsif word[0..1].include?("qu") #word beings with 'qu'. | |
result << word[2..-1] + word[0..1] + "ay" | |
else #word begins with 1 consonant. | |
result << word[1..-1] + word[0] + "ay" | |
end | |
else | |
result << word #word doesn't begin with a vowel or consonant. | |
end | |
result << " " unless word == word_list.last #add space after words except the last one. | |
end | |
return result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment