1 2 3 4 5 6 7 8 9 10 11 12 13
class WhoIsQuery query = ARGV[0] puts "Querying whois with #{query} ..." results = IO.popen("whois -Q #{query}") message = "No more domain for you!!" results.readlines.each do |line| if line.include?("No match for ") message = "Domain waiting for you..." break end end puts message end
Refactorings
No refactoring yet !
Jeremy Weiskotten
May 14, 2008, May 14, 2008 19:31, permalink
You can use Enumerable#any? instead of #each with a break...
1 2 3 4 5 6 7 8 9 10 11 12 13
class WhoIsQuery query = ARGV[0] puts "Querying whois with #{query} ..." results = IO.popen("whois -Q #{query}") message = if results.readlines.any? { |line| line.include?("No match for") } "Domain waiting for you..." else "No more domain for you!!" end puts message end
coderrr
May 23, 2008, May 23, 2008 17:34, permalink
no point in having the class if you aren't using it for anything
1 2 3 4 5 6 7 8 9
query = ARGV[0] puts "Querying whois with #{query} ..." message = if `whois -Q #{query}` =~ /no match for/i then "Domain waiting for you..." else "No more domain for you!!" end puts message
hugh Bien
May 23, 2008, May 23, 2008 17:55, permalink
make it one line for fun =]
1
puts "Querying whois with #{ARGV[0]} ...\n" + (`whois -Q #{ARGV[0]}` =~ /no match for/i ? "Domain waiting for you..." : "No more domain for you!!")
Peter Harkins
May 23, 2008, May 23, 2008 18:19, permalink
There are three Ruby whois libraries, you don't have to reinvent the wheel. And whois doesn't necessarily tell you that a domain is available for registration, you should be doing a DNS lookup.
I'm new to ruby and I make this quick program to check if a domain is available, can we improve it?