Created
January 8, 2016 08:21
-
-
Save krokrob/3a1509d20f0b28a741f1 to your computer and use it in GitHub Desktop.
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
# louchebem translator | |
# let's start with some pseudo-code | |
def louchebemize_word(word) | |
if word.length == 1 | |
return word | |
else | |
vowels = %w(a e i o u y) | |
letters = word.split("") | |
first_vowel_index = letters.find_index do |letter| | |
vowels.include? letter | |
end | |
begining = letters[first_vowel_index...letters.length].join("") | |
finishing = letters[0...first_vowel_index].join("") | |
random_suffix = ["em", "é", "ji", "oc", "ic", "uche", "ès"].sample | |
return "l#{begining}#{finishing}#{random_suffix}" | |
end | |
end | |
# p louchebemize_word("yaourt") | |
def louchebemize_sentence(sentence) | |
words = sentence.split(/\b/) | |
translated_words = [] | |
words.each do |word| | |
if word.match(/\W/) | |
translated_words << word | |
else | |
translated_words << louchebemize_word(word) | |
end | |
end | |
return translated_words.join("") | |
end | |
puts louchebemize_sentence("Salut, qu'est-ce que tu veux?") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment