Module: Clouddns::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/clouddns/utils.rb

Instance Method Summary collapse

Instance Method Details

#format_record(record, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/clouddns/utils.rb', line 13

def format_record record, options={}
  namelength = options[:namelength] || 20
  prefix = options[:prefix] || ''

  output = []

  record.value.each_with_index do |value, i|
    if i.zero?
      args = [prefix, record.type, record.ttl, record.name, value]
    else
      args = [prefix, '', '', '', value]
    end
    output << "%s%5s %5s %#{namelength}s %s" % args
  end

  output.join("\n")
end

#parse_domain(name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/clouddns/utils.rb', line 5

def parse_domain name
  if name =~ /\A(.*?\..*?)\.?\z/
    "#{$1}."
  else
    raise "Invalid domain: '#{name}'"
  end
end