Last active
December 24, 2015 01:29
-
-
Save rayning0/6724626 to your computer and use it in GitHub Desktop.
Tweet Shortener
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
def tweetsub(tweet) | |
tsub = {'to' => '2', 'two' => '2', 'too' => '2', 'for' => '4', | |
'four' => '4', 'be' => 'b', 'you' => 'u', 'at' => '@', 'and' => '&'} | |
tsub.keys.each do |key| | |
tweet.gsub!(key) {tsub[key]} | |
end | |
tweet | |
end | |
tweets = ["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!!!!", | |
"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.", | |
"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!"] | |
def short(tweets) | |
shorts = [] | |
tweets.each do |tw| | |
if tw.size > 140 | |
sh = tweetsub(tw) | |
sh = sh.slice(0, 140) if sh.size > 140 | |
else | |
sh = tw | |
end | |
shorts << sh | |
end | |
shorts | |
end | |
puts short(tweets) | |
# Output: | |
#Hey guys, can anyone teach me how 2 b cool? I really want 2 b the bst @ everything, u know wh@ I mean? Tweeting is super fun u guys!!!! | |
#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 4 u guys, which is weird, bcause I'm a writer & this is just writing & I tweet all day. For real, u guys. | |
#GUISEEEEE this is so fun! I'm tweeting 4 u guys & this tweet is SOOOO long it's gonna b way more than u would think twitter can h&le, so sho |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment