Created
September 18, 2013 16:39
-
-
Save camkidman/6611873 to your computer and use it in GitHub Desktop.
pig latin
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
def translate(string) | |
x = string | |
vowels = (/[aeiou]/) | |
withq = (/[aeio]/) | |
splitskies = x.split | |
if x =~ (/[qu]/) | |
vowels = withq | |
end | |
if splitskies.size > 1 | |
splitskies.map! do |w| | |
if w[0] =~ vowels | |
w = w + "ay" | |
elsif w[0] !~ vowels && w[1] !~ vowels && w[2] !~ vowels | |
w = w[3..-1] + w[0..2] + "ay" | |
elsif w[0] !~ vowels && w[1] !~ vowels | |
w = w[2..-1] + w[0..1] + "ay" | |
elsif w[0] !~ vowels | |
w = w[1..-1] + w[0] + 'ay' | |
end | |
end | |
else | |
if x[0] =~ vowels | |
x = x + "ay" | |
elsif x[0] !~ vowels && x[1] !~ vowels && x[2] !~ vowels | |
x = x[3..-1] + x[0..2] + "ay" | |
elsif x[0] !~ vowels && x[1] !~ vowels | |
x = x[2..-1] + x[0..1] + "ay" | |
elsif x[0] !~ vowels | |
l = x.slice!(0) | |
x = x + l + "ay" | |
end | |
end | |
return splitskies.join(' ') if splitskies.size > 1 | |
return x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment