Class: EventMachine::SnmpAgent::MibList
- Inherits:
-
Object
- Object
- EventMachine::SnmpAgent::MibList
- Defined in:
- lib/snmpagent/miblist.rb
Instance Method Summary collapse
- #add_object(oid, value) ⇒ Object
- #get(oid) ⇒ Object
- #get_next(oid) ⇒ Object
-
#initialize ⇒ MibList
constructor
A new instance of MibList.
Constructor Details
#initialize ⇒ MibList
Returns a new instance of MibList.
35 36 37 38 39 |
# File 'lib/snmpagent/miblist.rb', line 35 def initialize @hash = {} @set = SortedSet.new @successors = {} end |
Instance Method Details
#add_object(oid, value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/snmpagent/miblist.rb', line 41 def add_object oid, value if oid.is_a?(String) oid = oid.split(".").map {|a| a.to_i} end @set.add oid @hash [oid] = value @successors.clear prev = nil @set.each {|s| if prev @successors[prev] = s end prev = s } end |
#get(oid) ⇒ Object
60 61 62 63 |
# File 'lib/snmpagent/miblist.rb', line 60 def get oid h = @hash [oid] h.respond_to?(:call) ? h.call : h end |
#get_next(oid) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/snmpagent/miblist.rb', line 65 def get_next oid nextoid = if @successors.member?(oid) @successors[oid] else # Linear search. @set.find {|s| (oid <=> s) < 0 } end if nextoid [nextoid, get(nextoid)] end end |