Class: SNMP::ObjectId

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

Direct Known Subclasses

ObjectName

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = []) ⇒ ObjectId

Create an object id. The input is expected to be either a string in the format “n.n.n.n.n.n” or an array of integers.



135
136
137
138
139
140
141
142
143
# File 'lib/snmp/varbind.rb', line 135

def initialize(id=[])
    if id.respond_to? :to_str
        super(make_integers(id.to_str.split(".")))
    else
        super(make_integers(id.to_ary))
    end
rescue ArgumentError
    raise ArgumentError, "'#{id}' not a valid object ID"
end

Class Method Details

.decode(value_data) ⇒ Object



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

def self.decode(value_data)
    ObjectId.new(decode_object_id_value(value_data))
end

Instance Method Details

#asn1_typeObject



127
128
129
# File 'lib/snmp/varbind.rb', line 127

def asn1_type
    "OBJECT IDENTIFIER"
end

#encodeObject



157
158
159
# File 'lib/snmp/varbind.rb', line 157

def encode
    encode_object_id(self)
end

#inspectObject



153
154
155
# File 'lib/snmp/varbind.rb', line 153

def inspect
    "[#{self.to_s}]"
end

#subtree_of?(parent_tree) ⇒ Boolean

Returns true if this ObjectId is a subtree of the provided parent tree ObjectId. For example, “1.3.6.1.5” is a subtree of “1.3.6.1”.

Returns:

  • (Boolean)


165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/snmp/varbind.rb', line 165

def subtree_of?(parent_tree)
    unless parent_tree.kind_of? ObjectId
        parent_tree = ObjectId.new(parent_tree)
    end
    if parent_tree.length > self.length
        false
    else
        parent_tree.each_index do |i|
            return false if parent_tree[i] != self[i]
        end
        true
    end
end

#to_sObject



149
150
151
# File 'lib/snmp/varbind.rb', line 149

def to_s
    self.join('.')
end

#to_varbindObject



145
146
147
# File 'lib/snmp/varbind.rb', line 145

def to_varbind
    VarBind.new(self, Null)
end