Class: SNMP::Integer

Inherits:
Object
  • Object
show all
Extended by:
BER::Decode
Includes:
Comparable, BER::Encode
Defined in:
lib/snmp/varbind.rb

Direct Known Subclasses

Counter64, Integer32, UnsignedInteger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BER::Decode

assert_no_remainder, build_integer, decode_integer, decode_integer_value, decode_ip_address, decode_object_id, decode_object_id_value, decode_octet_string, decode_sequence, decode_timeticks, decode_tlv, decode_uinteger_value

Methods included from BER::Encode

#encode_exception, #encode_integer, #encode_length, #encode_null, #encode_object_id, #encode_octet_string, #encode_sequence, #encode_tagged_integer, #encode_tlv, #integer_to_octets

Constructor Details

#initialize(value) ⇒ Integer

Returns a new instance of Integer.



88
89
90
# File 'lib/snmp/varbind.rb', line 88

def initialize(value)
  @value = value.to_i
end

Class Method Details

.decode(value_data) ⇒ Object



80
81
82
# File 'lib/snmp/varbind.rb', line 80

def self.decode(value_data)
  Integer.new(decode_integer_value(value_data))
end

Instance Method Details

#<=>(other) ⇒ Object



92
93
94
95
# File 'lib/snmp/varbind.rb', line 92

def <=>(other)
  return nil unless other.respond_to? :to_i
  @value <=> other.to_i
end

#asn1_typeObject



84
85
86
# File 'lib/snmp/varbind.rb', line 84

def asn1_type
  "INTEGER"
end

#coerce(other) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/snmp/varbind.rb', line 97

def coerce(other)
  if other.kind_of? ::Integer
    return [other, @value]
  else
    return [other.to_f, self.to_f]
  end
end

#encodeObject



117
118
119
# File 'lib/snmp/varbind.rb', line 117

def encode
  encode_integer(@value)
end

#to_fObject



113
114
115
# File 'lib/snmp/varbind.rb', line 113

def to_f
  @value.to_f
end

#to_iObject



109
110
111
# File 'lib/snmp/varbind.rb', line 109

def to_i
  @value
end

#to_oidObject

Raises:

  • (RangeError)


121
122
123
124
# File 'lib/snmp/varbind.rb', line 121

def to_oid
  raise RangeError, "@{value} cannot be an OID (must be >0)" if @value < 0
  ObjectId.new([@value])
end

#to_sObject



105
106
107
# File 'lib/snmp/varbind.rb', line 105

def to_s
  @value.to_s
end