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.



71
72
73
# File 'lib/snmp/varbind.rb', line 71

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

Class Method Details

.decode(value_data) ⇒ Object



63
64
65
# File 'lib/snmp/varbind.rb', line 63

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

Instance Method Details

#<=>(other) ⇒ Object



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

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

#asn1_typeObject



67
68
69
# File 'lib/snmp/varbind.rb', line 67

def asn1_type
    "INTEGER"
end

#coerce(other) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/snmp/varbind.rb', line 79

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

#encodeObject



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

def encode
    encode_integer(@value)
end

#to_fObject



95
96
97
# File 'lib/snmp/varbind.rb', line 95

def to_f
    @value.to_f
end

#to_iObject



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

def to_i
    @value
end

#to_oidObject

Raises:

  • (RangeError)


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

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

#to_sObject



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

def to_s
    @value.to_s
end