Class: TweetSpeak

Inherits:
Object
  • Object
show all
Defined in:
lib/tweet_speak.rb

Constant Summary collapse

SHORTHAND =
{
  'are' => 'r',
  'you' => 'u',
  'your' => 'ur',
  "you're" => 'ur',
  'to' => '2',
  'because' => 'b/c',
  'before' => 'b4',
  'for' => '4',
  'with' => 'w/',
  'without' => 'w/o'
}

Class Method Summary collapse

Class Method Details

.twittify(tweet) ⇒ Object



15
16
17
18
19
20
# File 'lib/tweet_speak.rb', line 15

def self.twittify(tweet)
  regex = /(\W*)(#{SHORTHAND.keys.join('|')})(\W+|$)/i
  tweet.gsub(regex) do |match|
    $1 + SHORTHAND[$2] + $3
  end.gsub(/\s+/, ' ')
end