Created
January 17, 2019 18:46
-
-
Save rodloboz/77b7fce8f3668827ca3907d5be6cf903 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
# split the sentence into words | |
# ignore punctuation // filter words | |
# ignore one letter words | |
# shift initial consonant group to the end of each word | |
# add random suffix to the end | |
# pre-pend l to te beginning of each word | |
SUFFIXES = %w[em é ji oc ic uche ès].freeze | |
VOWELS = %w[a e i o u].freeze | |
def randomize | |
SUFFIXES.sample | |
end | |
def shift_consonants(word) | |
letters = word.chars | |
counter = 0 | |
letters.take_while do |letter| | |
counter += 1 unless VOWELS.include?(letter) | |
end | |
consonants = letters.shift(counter) | |
letters.push(consonants).flatten | |
end | |
def transform(word) | |
if word.size != 1 | |
# shift initial consonant group to the end of each word | |
letters = shift_consonants(word) | |
# add random suffix to the end | |
letters.push(randomize) | |
# pre-pend l to te beginning of each word | |
letters.unshift 'l' | |
letters.join | |
else | |
word | |
end | |
end | |
def louchebemize(sentence) | |
# TODO: implement your louchebem translator | |
# split the sentence into words | |
elements = sentence.split(/\b/) | |
translated_elements = elements.map do |element| | |
# transform if element is a word | |
element =~ /\W/ ? element : transform(element) | |
end | |
translated_elements.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment