File: ns.rb

package info (click to toggle)
ruby-net-dns 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 3,944; makefile: 6
file content (70 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
59
60
61
62
63
64
65
66
67
68
69
70
module Net # :nodoc:
  module DNS
    class RR
      #
      # = Name Server Record (NS)
      #
      # Class for DNS NS resource records.
      #
      class NS < RR
        # Gets the name server value.
        #
        # Returns a String.
        attr_reader :nsdname

        # Gets the standardized value for this record,
        # represented by the value of <tt>nsdname</tt>.
        #
        # Returns a String.
        def value
          nsdname.to_s
        end

        private

        def subclass_new_from_hash(options)
          if options.key?(:nsdname)
            @nsdname = check_name(options[:nsdname])
          else
            raise ArgumentError, ":nsdname field is mandatory"
          end
        end

        def subclass_new_from_string(str)
          @nsdname = check_name(str)
        end

        def subclass_new_from_binary(data, offset)
          @nsdname, offset = dn_expand(data, offset)
          offset
        end

        def set_type
          @type = Net::DNS::RR::Types.new("NS")
        end

        def get_inspect
          value
        end

        def check_name(input)
          name = input.to_s
          unless name =~ /(\w\.?)+\s*$/ && name =~ /[a-zA-Z]/
            raise ArgumentError, "Invalid Name Server `#{name}'"
          end

          name
        end

        def build_pack
          @nsdname_pack = pack_name(@nsdname)
          @rdlength = @nsdname_pack.size
        end

        def get_data
          @nsdname_pack
        end
      end
    end
  end
end