module TwitterUsernameExtractor

Constants

VERSION

Public Class Methods

extract(t) click to toggle source
# File lib/twitter_username_extractor.rb, line 6
def self.extract(t)
  return if t.to_s.empty?
  return Regexp.last_match(1) if t.match(/^\@(\w+)$/)
  return Regexp.last_match(1) if t.match(/^(\w+)$/)
  return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)$}i)

  # Odd special cases
  return Regexp.last_match(1) if t.match(%r{twitter.com/search\?q=%23(\w+)}i)
  return Regexp.last_match(1) if t.match(%r{twitter.com/#!/https://twitter.com/(\w+)}i)
  return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/#!/(\w+)[/\?]?}i)
  return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)[\/]?}i)
  fail Error, "Unknown twitter handle: #{t}"
end