Class: Turboname::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/turboname/domain.rb

Constant Summary collapse

CountryTLDs =
%w{ac ad ae af ag ai al am an ao aq ar as at au aw ax az ba bb bd be bf bg bh bi bj bm bn bo br bs bt bu bv bw by bz ca cc cd cf cg ch ci ck cl cm cn co cr cs cu cv cx cy cz de dj dk dm do dz ec ee eg eh er es et eu fi fj fk fm fo fr ga gb gd ge gf gg gh gi gl gm gn gp gq gr gs gt gu gw gy hk hm hn hr ht hu id ie il im in io iq ir is it je jm jo jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md me mg mh mk ml mm mn mo mp mq mr ms mt mu mv mw mx my mz na nc ne nf ng ni nl no np nr nu nz om pa pe pf pg ph pk pl pm pn pr ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr st su sv sy sz tc td tf tg tj tk tl tm tn to tp tr tt tv tw tz ua ug uk us uy uz va vc ve vg vi vn vu wf ws ye yt yu za zm zw}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Domain

Returns a new instance of Domain.



7
8
9
# 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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/turboname/domain.rb', line 5

def name
  @name
end

Instance Method Details

#available?(tld = nil) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

#lengthObject



44
45
46
# File 'lib/turboname/domain.rb', line 44

def length
  @name.length
end

#save(tld = 'com') ⇒ Object



16
17
18
# File 'lib/turboname/domain.rb', line 16

def save tld = 'com'
  `echo "#{with_tld(tld)}" >> names.txt`
end

#tldizeObject



34
35
36
37
# File 'lib/turboname/domain.rb', line 34

def tldize
  last_letters = self.name[-2..-1]
  last_letters if CountryTLDs.include?(last_letters)
end

#to_sObject

this will not include the tld



40
41
42
# File 'lib/turboname/domain.rb', line 40

def to_s
  @name
end

#with_tld(tld) ⇒ Object

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



12
13
14
# 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