Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created October 12, 2013 21:39
Show Gist options
  • Save irmiller22/6955214 to your computer and use it in GitHub Desktop.
Save irmiller22/6955214 to your computer and use it in GitHub Desktop.
tweet_substitute
require 'pry'
tweet1 = "Hey guys, can anyone teach me how to be cool? I really want to be the best at everything, you know what I mean? Tweeting is super fun you guys!!!!"
tweet2 = "OMG you guys, you won't believe how sweet my kitten is. My kitten is like super cuddly and too cute to be believed right?", "I'm running out of example tweets for you guys, which is weird, because I'm a writer and this is just writing and I tweet all day. For real, you guys. For real."
tweet3 = "GUISEEEEE this is so fun! I'm tweeting for you guys and this tweet is SOOOO long it's gonna be way more than you would think twitter can handle, so shorten it up you know what I mean? I just can never tell how long to keep typing!"
@substitute = {"to" => "2","too" => "2","two" => "2","for" => "4","four" => "4","be" => "b","you" => "u","at" => "@","and" => "&"}
def tweet_shortener(tweet)
tweet_words = tweet.split(" ")
tweet_words.each_index do |i|
@substitute.each do |word, substitute|
if tweet_words[i] == word
tweet_words[i] = substitute
end
end
end
tweet = tweet_words.join(" ")
if tweet.size >= 140
tweet.slice(0, 140)
else
tweet
end
end
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment