Class: Dnsruby::Classes

Inherits:
CodeMapper show all
Defined in:
lib/dnsruby.rb

Constant Summary collapse

IN =

RFC 1035

1
CH =

RFC 1035

3
HS =

CHAOS = 3 # RFC 1035

4
NONE =

HESIOD = 4 # RFC 1035

254
ANY =

RFC 2136

255

Instance Attribute Summary

Attributes inherited from CodeMapper

#code, #string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CodeMapper

#<=>, #==, add_pair, #initialize, #inspect, maxcode, method_missing, regexp, #set_code, #set_string, to_code, to_string, update

Constructor Details

This class inherits a constructor from Dnsruby::CodeMapper

Class Method Details

.classesbyname(name) ⇒ Object

classesbyval and classesbyname functions are wrappers around the similarly named hashes. They are used for ‘unknown’ DNS RR classess (RFC3597)

See typesbyval and typesbyname, these beasts have the same functionality



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/dnsruby.rb', line 172

def Classes.classesbyname(name) #:nodoc: all
  name.upcase!;
  if to_code(name)
    return to_code(name)
  end
  
  if ((name =~/^\s*CLASS(\d+)\s*$/o) == nil)
    raise ArgumentError, "classesbyval() argument is not CLASS### (#{name})"
  end
  
  val = $1.to_i
  if val > 0xffff
    raise ArgumentError, 'classesbyval() argument larger than ' + 0xffff
  end
  
  return val;
end

.classesbyval(val) ⇒ Object

:nodoc: all

Raises:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/dnsruby.rb', line 192

def Classes.classesbyval(val) #:nodoc: all
  if (val.class == String)
    if ((val =~ /^\s*0*([0-9]+)\s*$/) == nil)
      raise ArgumentError,  "classesbybal() argument is not numeric (#{val})" # unless  val.gsub!("^\s*0*([0-9]+)\s*$", "$1")
      #          val =~ s/^\s*0*([0-9]+)\s*$/$1/o;#
    end
    val = $1.to_i
  end
  
  return to_string(val) if to_string(val)
  
  raise ArgumentError,  'classesbyval() argument larger than ' + 0xffff if val > 0xffff;
  
  return "CLASS#{val}";
end

Instance Method Details

#unknown_code(arg) ⇒ Object



163
164
165
166
# File 'lib/dnsruby.rb', line 163

def unknown_code(arg)
  Classes.add_pair('CLASS' + arg.to_s, arg)
  set_code(arg)
end

#unknown_string(arg) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/dnsruby.rb', line 154

def unknown_string(arg)
  if (arg=~/^CLASS/i)
    Classes.add_pair(arg, arg.gsub('CLASS', '').to_i)
    set_string(arg)
  else
    raise ArgumentError.new("String #{arg} not a member of #{self.class}")
  end
end