class Twexicon::Validator
Constants
- TWITTER_RESERVED_WORDS
Attributes
username[R]
Public Class Methods
new()
click to toggle source
# File lib/twexicon/validator.rb, line 6 def initialize @username = "" end
Public Instance Methods
is_valid?()
click to toggle source
# File lib/twexicon/validator.rb, line 33 def is_valid? username.match(/^\w{1,15}$/) && !TWITTER_RESERVED_WORDS.include?(username.downcase) end
run()
click to toggle source
# File lib/twexicon/validator.rb, line 10 def run until username.length > 0 puts "\nPlease enter a valid Twitter handle:" @username = gets.gsub(/\W/, "") until is_valid? puts "Sorry, that doesn't seem to be a valid Twitter account. Please try again." @username = gets.gsub(/\W/, "") end begin @username = Nokogiri::HTML(open("https://twitter.com/#{username}")).css("span.u-linkComplex-target").first.text rescue OpenURI::HTTPError, NoMethodError puts "Hm, that doesn't seem to be an active Twitter account." @username = "" run rescue SocketError puts "Sorry, the network isn't responding. Please try again." @username = "" run end end "#{username}" end