class Turboname::Domain

Constants

CountryTLDs

Attributes

name[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/turboname/domain.rb, line 7
def initialize opts = {}
  self.name = opts[:from].respond_to?(:get) ? opts[:from].get : opts[:from] if opts[:from]
end

Public Instance Methods

available?(tld = nil) click to toggle source
# File lib/turboname/domain.rb, line 20
def available? tld = nil
  tld = 'com' if tld.nil?
  name_with_tld = with_tld(tld)
  print name_with_tld
  begin
    domain = Whois.whois(name_with_tld)
    available = domain.available?
  rescue
    available = false
  end
  puts "#{' '*(25 - name_with_tld.length)}#{available ? 'IS' : 'is not'} available"
  available
end
length() click to toggle source
# File lib/turboname/domain.rb, line 44
def length
  @name.length
end
save(tld = 'com') click to toggle source
# File lib/turboname/domain.rb, line 16
def save tld = 'com'
  `echo "#{with_tld(tld)}" >> names.txt`
end
tldize() click to toggle source
# File lib/turboname/domain.rb, line 34
def tldize
  last_letters = self.name[-2..-1]
  last_letters if CountryTLDs.include?(last_letters)
end
to_s() click to toggle source

this will not include the tld

# File lib/turboname/domain.rb, line 40
def to_s
  @name
end
with_tld(tld) click to toggle source

let's remove the tld at the end of the domain. eljojo -> eljo.jo | asdfk -> asdfk.jo

# File lib/turboname/domain.rb, line 12
def with_tld tld
  @name[-tld.length..-1] == tld ? @name[0..-tld.length-1] + ".#{tld}" : "#{@name}.#{tld}"
end