Class: Whos::Check

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCheck

Returns a new instance of Check.



7
8
9
10
# File 'lib/whos/check.rb', line 7

def initialize
  @spam = Whos::Spam.new
  @responses = {}
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



5
6
7
# File 'lib/whos/check.rb', line 5

def responses
  @responses
end

Instance Method Details

#available?(domain) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/whos/check.rb', line 12

def available? domain
  response = `whois #{domain}`

  if response =~ /^(No match for|Not found)/i
    true
  else
    responses[domain] = @spam.filter(response)
    false
  end
end

#many(names) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/whos/check.rb', line 27

def many names
  domains = names.map do |domain|
    if domain =~ /\./
      print "Checking... "
      domain
    else
      puts "Checking #{domain}.#{tlds.join(',')}..."
      tlds.map do |tld|
        "#{domain}.#{tld}"
      end
    end
  end.flatten

  domains.peach do |domain|
    if available? domain
      print "#{domain} AVAILABLE!\n"
    else
      print "#{domain} taken :-(\n"
      `open http://#{domain}` if $open
    end
  end

  if $verbose
    domains.each do |domain|
      if responses[domain]
        puts
        puts "== #{domain} =="
        puts responses[domain]
      end
    end
  end
end

#tldsObject



23
24
25
# File 'lib/whos/check.rb', line 23

def tlds
  %w{com net org biz info us cc it}
end