Class: SNMP::Integer

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/snmp/varbind.rb

Direct Known Subclasses

Counter64, Integer32, UnsignedInteger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Integer

Returns a new instance of Integer


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

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

Class Method Details

.decode(value_data) ⇒ Object


76
77
78
# File 'lib/snmp/varbind.rb', line 76

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

Instance Method Details

#<=>(other) ⇒ Object


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

def <=>(other)
  @value <=> other.to_i
end

#asn1_typeObject


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

def asn1_type
  "INTEGER"
end

#coerce(other) ⇒ Object


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

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

#encodeObject


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

def encode
  encode_integer(@value)
end

#to_fObject


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

def to_f
  @value.to_f
end

#to_iObject


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

def to_i
  @value
end

#to_oidObject

Raises:

  • (RangeError)

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

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

#to_sObject


100
101
102
# File 'lib/snmp/varbind.rb', line 100

def to_s
  @value.to_s
end