Class: Netdisco::SNMP::VBHash
- Inherits:
-
Hash
- Object
- Hash
- Netdisco::SNMP::VBHash
- Defined in:
- lib/netdisco/snmp.rb
Overview
Hash with some helper methods to easier work with VarBinds
Instance Method Summary collapse
-
#[](*args) ⇒ SNMP::VarBind
Matching element.
-
#by_oid(*oid) ⇒ VBHash
精确查询.
-
#by_partial(*args) ⇒ SNMP::VarBind?
模糊匹配.
- #org_bracket ⇒ Object
Instance Method Details
#[](*args) ⇒ SNMP::VarBind
Returns matching element.
122 123 124 |
# File 'lib/netdisco/snmp.rb', line 122 def [](*args) org_bracket arg_to_oid(*args) end |
#by_oid(*oid) ⇒ VBHash
精确查询
95 96 97 98 99 100 101 102 |
# File 'lib/netdisco/snmp.rb', line 95 def by_oid(*oid) oid = arg_to_oid(*oid) hash = select do |key, value| key[0..oid.size - 1] == oid end new_hash = VBHash.new new_hash.merge hash end |
#by_partial(*args) ⇒ SNMP::VarBind?
模糊匹配
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/netdisco/snmp.rb', line 107 def by_partial(*args) oid = arg_to_oid(*args) # got = nil keys.each do |key| return self[key] if key.each_cons(oid.size).find { |e| e == oid } # if key.each_cons(oid.size).find { |e| e == oid } # got = self[key] # break # end end nil end |
#org_bracket ⇒ Object
89 |
# File 'lib/netdisco/snmp.rb', line 89 alias :org_bracket :[] |