Skip to content

Instantly share code, notes, and snippets.

@gregeng
Created September 27, 2013 02:42
Show Gist options
  • Save gregeng/6723514 to your computer and use it in GitHub Desktop.
Save gregeng/6723514 to your computer and use it in GitHub Desktop.
Day 4: Another Homework - Tweet Shortener
# Tweet Keyword Shortener
# "to, two, too" become '2'
# "for, four" become '4'
# 'be' becomes 'b'
# 'you' becomes 'u'
# "at" becomes "@"
# "and" becomes "&"
# Possible Regexes
# (/to|two|too/)
# (/for|four/)
# (/be/) - not working, but don't need for single words
# (/you/) - not working, but don't need for single words
# (/at/) - not working, but don't need for single words
# (/and/) - not working, but don't need for single words
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 tweet_shortener(tweet)
tweet.downcase
tweet.gsub!(/too|two|to/, "2")
tweet.gsub!(/for|four/, "4")
tweet.gsub!(" be ", " b ")
tweet.gsub!(" you ", " u ")
tweet.gsub!(" at ", " @ ")
tweet.gsub!(" and ", " & ")
end
def multi_tweet_shortener(tweets)
tweets.each do |x|
if x.length > 140
tweet_shortener(x)
if x.length > 140
x = x.slice!(0..139)
end
end
puts "#{x} \n\n"
end
end
multi_tweet_shortener(tweets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment