Class: SNMP::IpAddress
- Inherits:
-
Object
- Object
- SNMP::IpAddress
- Defined in:
- lib/snmp/varbind.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #asn1_type ⇒ Object
- #encode ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(value_data) ⇒ IpAddress
constructor
Create an IpAddress object.
-
#to_s ⇒ Object
Returns a formatted, dot-separated string representing this IpAddress.
-
#to_str ⇒ Object
Returns a raw four-octet string representing this IpAddress.
Constructor Details
#initialize(value_data) ⇒ IpAddress
Create an IpAddress object. The constructor accepts either a raw four-octet string or a formatted string of integers separated by dots (i.e. “10.1.2.3”).
202 203 204 205 206 207 208 209 |
# File 'lib/snmp/varbind.rb', line 202 def initialize(value_data) if value_data.length > 4 value_data = parse_string(value_data) elsif value_data.length != 4 raise InvalidIpAddress, "Expected 4 octets or formatted string, got #{value_data.inspect}" end @value = value_data end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
227 228 229 230 231 232 233 |
# File 'lib/snmp/varbind.rb', line 227 def ==(other) if other.respond_to? :to_str return @value.eql?(other.to_str) else return false end end |
#asn1_type ⇒ Object
193 194 195 |
# File 'lib/snmp/varbind.rb', line 193 def asn1_type "IpAddress" end |
#encode ⇒ Object
243 244 245 |
# File 'lib/snmp/varbind.rb', line 243 def encode encode_tlv(IpAddress_TAG, @value) end |
#eql?(other) ⇒ Boolean
235 236 237 |
# File 'lib/snmp/varbind.rb', line 235 def eql?(other) self == other end |
#hash ⇒ Object
239 240 241 |
# File 'lib/snmp/varbind.rb', line 239 def hash @value.hash end |
#to_s ⇒ Object
Returns a formatted, dot-separated string representing this IpAddress.
221 222 223 224 225 |
# File 'lib/snmp/varbind.rb', line 221 def to_s octets = [] @value.each_byte { |b| octets << b.to_s } octets.join('.') end |
#to_str ⇒ Object
Returns a raw four-octet string representing this IpAddress.
214 215 216 |
# File 'lib/snmp/varbind.rb', line 214 def to_str @value.dup end |