Last active
April 18, 2019 05:25
-
-
Save LucasCioffi/c9f229f1d5470db1044f1d9a99c4b743 to your computer and use it in GitHub Desktop.
Here's a controller action you could insert into a Rails project. Accept a block of text and transform it into the language of Fake Grimlock. http://fakegrimlock.com/ Creative Commons Attribution License 3.0.
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 fake_grimlockify | |
if params[:text].present? | |
@text_output = "" | |
params[:text].split(" ").each do |word| | |
if word.size > 4 | |
@text_output += word.singularize.upcase + " " #.force_encoding('UTF-16').gsub("\xE2\x80\x99","").force_encoding('UTF-8') | |
else | |
@text_output += word.upcase + " " #.force_encoding('UTF-16').gsub("\xE2\x80\x99","").force_encoding('UTF-8') | |
end | |
end | |
punctuation_marks = [" ",",",".","!","?",":","-"] | |
# delete whole words | |
# "\n", | |
["IS","SO","THE","A","AN","IF","HOW","THESE","THOSE","MY","HE","THEY","WE","SHE","IT","THAT","FOR","WHICH","WHO","WHOSE","OUR","IN","ON","ABOUT","AT","OF","YOUR","BY","HIS","THEIR","ITS","AM","ARE","BE","BEEN","BEING","CAN","COULD","DO","DONE","DOES","HAD","HAS","HAVE","MAY","MIGHT","MUST","SHALL","SHOULD","WAS","WERE","WILL","WOULD"].each do |word| | |
# at beginning | |
if @text_output[0..(word.size)] == word + " " | |
@text_output = @text_output[(word.size)..-1] | |
end | |
# in middle | |
@text_output = @text_output.gsub(" " + word + " "," ") | |
# at end | |
punctuation_marks.each do |punctuation| | |
@text_output = @text_output.gsub(" " + word + punctuation,punctuation) | |
end | |
end | |
# hard substitution anywhere it's found | |
["'S ","","\""].each do |word| | |
@text_output = @text_output.gsub(word,"") | |
end | |
# substitute at end of word | |
# [["",""]].each do |word| | |
# @text_output = @text_output.gsub(word[0] + " ",word[1] + " ") | |
# end | |
# substitute at beginning of word | |
[["AND",","]].each do |word| | |
@text_output = @text_output.gsub(" " + word[0] + " ",word[1] + " ") | |
end | |
# substituted B for A; must follow the substitution for "AND" | |
#["I’M","ME"] | |
[["US","ALL"],["THEY","ALL"],["I","ME"],["I'M","ME"],["FOR","NEED"],["TO","FOR"],["LIKES","LIKE"],["HER","OWN"],["DID","DONE"],[".,",","],["GOING","GO"]].each do |word| | |
# at beginning | |
if @text_output[0..(word.size-1)] == word | |
@text_output = word[1] + " " + @text_output[0..(word.size-1)] | |
end | |
# in middle | |
@text_output = @text_output.gsub(" " + word[0] + " "," " + word[1] + " ") | |
# at end | |
punctuation_marks.each do |punctuation| | |
@text_output = @text_output.gsub(" " + word[0] + punctuation," " + word[1] + punctuation) | |
end | |
end | |
# substitute at end of word + S | |
["B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"].each do |letter| | |
@text_output = @text_output.gsub("THING","replacecode1") | |
@text_output = @text_output.gsub("SS","replacecode2") | |
punctuation_marks.each do |punctuation| | |
@text_output = @text_output.gsub(letter + "ING" + punctuation,letter + "ED" + punctuation) | |
@text_output = @text_output.gsub(letter + "ED" + punctuation,letter + "ING" + punctuation) | |
@text_output = @text_output.gsub(letter + "S" + punctuation,letter + punctuation) | |
end | |
@text_output = @text_output.gsub("replacecode2","SS") | |
@text_output = @text_output.gsub("replacecode1","THING") | |
end | |
# add some classic FAKE GRIMLOCK phrases in there somewhere | |
if @text_output.size > 100 | |
@text_output = @text_output[0..99] + @text_output[100..-1].sub(". ",". OR ELSE. ") | |
elsif @text_output.size > 200 | |
@text_output = @text_output[0..199] + @text_output[200..-1].sub(". ",". AWESOME. ") | |
elsif @text_output.size > 300 | |
@text_output = @text_output[0..299] + @text_output[300..-1].sub(". ",". LOOK AROUND- IT ALREADY HAPPENED. ") | |
elsif @text_output.size > 400 | |
@text_output = @text_output[0..399] + @text_output[400..-1].sub(". ",". BECAUSE AWESOME. ") | |
elsif @text_output.size > 500 | |
@text_output = @text_output[0..499] + @text_output[500..-1].sub(". ",". COFFEE, BEER, BACON, HUMANS. ") | |
end | |
# # change contractions | |
# ["WON\’T","CAN\’T","DON\’T","MUSTN\’T","HAVEN\’T"].each do |contraction| | |
# @text_output = @text_output.gsub(contraction,"NOT") | |
# end | |
# #I'd, We'd, WE'll | |
# remove duplicate words | |
["OWN",","].each do |word| | |
@text_output = @text_output.gsub(word + " " + word, word) | |
end | |
# remove "I" at beginning of text | |
@text_output = "ME " + @text_output[2..-1] if @text_output[0..1] == "I " | |
# remove duplicate characters | |
[","].each do |character| | |
@text_output = @text_output.gsub(character + character, character) | |
end | |
end | |
respond_to do |format| | |
format.html | |
format.js | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment