Class: Snmp2mkr::Oid
- Inherits:
-
Object
- Object
- Snmp2mkr::Oid
- Defined in:
- lib/snmp2mkr/oid.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #index_of(o) ⇒ Object
-
#initialize(obj, mib: nil, name: nil) ⇒ Oid
constructor
A new instance of Oid.
- #inspect ⇒ Object
- #subtree?(o) ⇒ Boolean
- #subtree_of?(o) ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(obj, mib: nil, name: nil) ⇒ Oid
Returns a new instance of Oid.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/snmp2mkr/oid.rb', line 11 def initialize(obj, mib: nil, name: nil) case obj when Array @ary = obj.map(&:to_i) when String if obj.include?('::') @name = obj @ary = mib.name_to_oid(obj) else @ary = obj.split('.').map(&:to_i) end end @str = @ary.map(&:to_s).join('.') case when name @name = name when mib @name ||= mib.oid_to_name(self) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/snmp2mkr/oid.rb', line 33 def name @name end |
Instance Method Details
#==(o) ⇒ Object
43 44 45 |
# File 'lib/snmp2mkr/oid.rb', line 43 def ==(o) self.class == o.class && self.to_s == o.to_s end |
#index_of(o) ⇒ Object
58 59 60 61 62 |
# File 'lib/snmp2mkr/oid.rb', line 58 def index_of(o) other = Snmp2mkr::Oid(o) raise ArgumntError, "#{o.inspect} is not subtree of #{self.inspect} " unless other.subtree?(self) self.to_a[other.to_a.size..-1].map(&:to_s).join('.') end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/snmp2mkr/oid.rb', line 64 def inspect "#<#{self.class}: #{to_s}#{@name && " (#{@name})"}>" end |
#subtree?(o) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/snmp2mkr/oid.rb', line 47 def subtree?(o) other = Snmp2mkr::Oid(o) self.to_a.size < other.to_a.size && other.to_a[0,self.to_a.size] == self.to_a end |
#subtree_of?(o) ⇒ Boolean
53 54 55 56 |
# File 'lib/snmp2mkr/oid.rb', line 53 def subtree_of?(o) other = Snmp2mkr::Oid(o) other.subtree?(self) end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/snmp2mkr/oid.rb', line 35 def to_a @ary end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/snmp2mkr/oid.rb', line 39 def to_s @str end |