Class: Dnsruby::CodeMapper
- Inherits:
-
Object
- Object
- Dnsruby::CodeMapper
- Includes:
- Comparable
- Defined in:
- lib/dnsruby/code_mapper.rb
Overview
Direct Known Subclasses
Algorithms, Classes, ExtendedRCode, Message::SecurityLevel, MetaTypes, Modes, Nsec3HashAlgorithms, OpCode, QTypes, RCode, RR::CERT::CertificateTypes, RR::DS::DigestTypes, RR::SSHFP::Algorithms, RR::SSHFP::FpTypes, Types
Defined Under Namespace
Classes: Arrays
Constant Summary collapse
- @@arrays =
{}
- @@lock =
Serialize native numeric inserts without holding a lock across application-defined string/hash methods.
Mutex.new
Instance Attribute Summary collapse
-
#code ⇒ Object
(also: #to_code, #to_i)
Returns the value of attribute code.
-
#string ⇒ Object
(also: #to_string, #to_s)
Returns the value of attribute string.
Class Method Summary collapse
-
.method_missing(methId) ⇒ Object
:nodoc: all.
-
.regexp ⇒ Object
Return a regular expression which matches any codes or strings from the CodeMapper.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(arg) ⇒ CodeMapper
constructor
:nodoc: all.
- #inspect ⇒ Object
- #set_code(arg) ⇒ Object
- #set_string(arg) ⇒ Object
-
#unknown_code(arg) ⇒ Object
:nodoc: all.
-
#unknown_string(arg) ⇒ Object
:nodoc: all.
Constructor Details
#initialize(arg) ⇒ CodeMapper
:nodoc: all
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/dnsruby/code_mapper.rb', line 122 def initialize(arg) #:nodoc: all array = @@arrays[self.class] if (arg.kind_of?String) arg = arg.gsub("_", "-") code = array.stringsdown[arg.downcase] if (code != nil) @code = code @string = array.values[@code] else unknown_string(arg) end elsif arg.kind_of?(Integer) if (array.values[arg] != nil) @code = arg @string = array.values[@code] else unknown_code(arg) end elsif (arg.kind_of?self.class) @code = arg.code @string = array.values[@code] else raise ArgumentError.new("Unknown argument of type #{arg.class}: #{arg} for #{self.class}") end end |
Instance Attribute Details
#code ⇒ Object Also known as: to_code, to_i
Returns the value of attribute code.
34 35 36 |
# File 'lib/dnsruby/code_mapper.rb', line 34 def code @code end |
#string ⇒ Object Also known as: to_string, to_s
Returns the value of attribute string.
34 35 36 |
# File 'lib/dnsruby/code_mapper.rb', line 34 def string @string end |
Class Method Details
.method_missing(methId) ⇒ Object
:nodoc: all
117 118 119 120 |
# File 'lib/dnsruby/code_mapper.rb', line 117 def self.method_missing(methId) #:nodoc: all str = methId.id2name return self.new(str) end |
.regexp ⇒ Object
Return a regular expression which matches any codes or strings from the CodeMapper.
201 202 203 204 |
# File 'lib/dnsruby/code_mapper.rb', line 201 def self.regexp # Longest ones go first, so the regex engine will match AAAA before A, etc. return @@arrays[self].strings.keys.sort { |a, b| b.length <=> a.length }.join('|') end |
Instance Method Details
#<=>(other) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/dnsruby/code_mapper.rb', line 183 def <=>(other) if other.is_a?(Integer) self.code <=> other else self.code <=> other.code end end |
#==(other) ⇒ Object Also known as: eql?
191 192 193 194 195 196 197 |
# File 'lib/dnsruby/code_mapper.rb', line 191 def ==(other) return true if [@code, @string].include?other if (CodeMapper === other) return true if ((other.code == @code) || (other.string == @string)) end return false end |
#hash ⇒ Object
159 160 161 |
# File 'lib/dnsruby/code_mapper.rb', line 159 def hash @code end |
#inspect ⇒ Object
163 164 165 |
# File 'lib/dnsruby/code_mapper.rb', line 163 def inspect return @string end |
#set_code(arg) ⇒ Object
154 155 156 157 |
# File 'lib/dnsruby/code_mapper.rb', line 154 def set_code(arg) @code = arg @string = @@arrays[self.class].values[@code] end |
#set_string(arg) ⇒ Object
148 149 150 151 152 |
# File 'lib/dnsruby/code_mapper.rb', line 148 def set_string(arg) array = @@arrays[self.class] @code = array.stringsdown[arg.downcase] @string = array.values[@code] end |
#unknown_code(arg) ⇒ Object
:nodoc: all
110 111 112 113 114 115 |
# File 'lib/dnsruby/code_mapper.rb', line 110 def unknown_code(arg) #:nodoc: all # Be liberal in what you accept... # raise ArgumentError.new("Code #{arg} not a member of #{self.class}") self.class.add_pair(arg.to_s, arg) set_code(arg) end |
#unknown_string(arg) ⇒ Object
:nodoc: all
106 107 108 |
# File 'lib/dnsruby/code_mapper.rb', line 106 def unknown_string(arg) #:nodoc: all raise ArgumentError.new("String #{arg} not a member of #{self.class}") end |