Class: Domain

Inherits:
Object show all
Defined in:
lib/vagrant-dnsmasq/includes/Domain.class.rb

Constant Summary collapse

MATCH =
/^\.?[a-z]*$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Domain

Returns a new instance of Domain.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant-dnsmasq/includes/Domain.class.rb', line 5

def initialize(name)
  @name = nil

  if name.is_a? Domain
    @name = name.dotted
    return
  end

  raise ArgumentError, "no domain name given" unless name

  # parse domain name ...
  name = name.to_s
  name = name[1..-1] if name.start_with? '.'
  name = name.downcase
  raise ArgumentError, "Domain '#{name}' must match #{MATCH}" unless Domain::valid?(name)
  @name = name # without leading .   
end

Class Method Details

.valid?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/vagrant-dnsmasq/includes/Domain.class.rb', line 23

def self.valid?(name)
  Domain::MATCH.match(name.downcase)
end

Instance Method Details

#dottedObject



27
28
29
# File 'lib/vagrant-dnsmasq/includes/Domain.class.rb', line 27

def dotted
  '.' + @name
end

#nameObject



31
32
33
# File 'lib/vagrant-dnsmasq/includes/Domain.class.rb', line 31

def name
  @name
end

#to_sObject



35
36
37
# File 'lib/vagrant-dnsmasq/includes/Domain.class.rb', line 35

def to_s
  dotted
end