Skip to content

Instantly share code, notes, and snippets.

@rodloboz
Created January 17, 2019 18:26
Show Gist options
  • Save rodloboz/6d58686b1c4add9ce6f402fc76a14848 to your computer and use it in GitHub Desktop.
Save rodloboz/6d58686b1c4add9ce6f402fc76a14848 to your computer and use it in GitHub Desktop.
# 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)
characters = word.chars
counter = 0
characters.take_while do |c|
counter += 1 unless VOWELS.include?(c)
end
consonants = characters.shift(counter)
characters.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
words = sentence.split(/\b/)
new_sentence = words.map { |word| word =~ /\W/ ? word : transform(word) }
new_sentence.join
end
# <h1>Hello world!</h1>
# <p style="color: red">This is a paragraph</p>
# [attr_name, attr_value]
# <p></p>
def tag(tag_name, attributes = nil)
attr_string = ""
# false nil
if attributes # if there are attributes
attr_string = " #{attributes[0]}=\"#{attributes[1]}\""
end
content = yield if block_given? # executes the block
"<#{tag_name}#{attr_string}>#{content}</#{tag_name}>"
end
puts tag("p", ["style", "color: red"]) { "This is a paragraph" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment