Class: SNMP::ObjectId

### Home Classes Methods

### In Files

- lib/snmp/varbind.rb

### Parent

Array

### Methods

- ::decode
- ::new
- #asn1_type
- #encode
- #index
- #inspect
- #subtree_of?
- #to_oid
- #to_s
- #to_str
- #to_varbind
- #with_mib

### Included Modules

- Comparable

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- SNMP
- SNMP::BER
- SNMP::Counter32
- SNMP::Counter64
- SNMP::EndOfMibView
- SNMP::Gauge32
- SNMP::GetBulkRequest
- SNMP::GetNextRequest
- SNMP::GetRequest
- SNMP::InformRequest
- SNMP::Integer
- SNMP::Integer32
- SNMP::InvalidErrorStatus
- SNMP::InvalidGenericTrap
- SNMP::InvalidIpAddress
- SNMP::InvalidPduTag
- SNMP::InvalidTrapVarbind
- SNMP::IpAddress
- SNMP::MIB
- SNMP::MIB::ModuleNotLoadedError
- SNMP::Manager
- SNMP::Manager::Config
- SNMP::Message
- SNMP::NoSuchInstance
- SNMP::NoSuchObject
- SNMP::Null
- SNMP::ObjectId
- SNMP::ObjectName
- SNMP::OctetString
- SNMP::Opaque
- SNMP::PDU
- SNMP::ParseError
- SNMP::RequestId
- SNMP::RequestTimeout
- SNMP::Response
- SNMP::SNMPv1_Trap
- SNMP::SNMPv2_Trap
- SNMP::SetRequest
- SNMP::TimeTicks
- SNMP::TrapListener
- SNMP::TrapListener::Config
- SNMP::UDPServerTransport
- SNMP::UDPTransport
- SNMP::Unsigned32
- SNMP::UnsignedInteger
- SNMP::UnsupportedPduTag
- SNMP::UnsupportedValueTag
- SNMP::UnsupportedVersion
- SNMP::VarBind
- SNMP::VarBindList
- Fixnum
- Object

No matching classes.

# SNMP::ObjectId

### Public Class Methods

decode(value_data, mib=nil) click to toggle source

    # File lib/snmp/varbind.rb, line 140
    def self.decode(value_data, mib=nil)
      ObjectId.new(decode_object_id_value(value_data), mib)
    end

new(id=[], mib=nil) click to toggle source

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.

    # File lib/snmp/varbind.rb, line 152
    def initialize(id=[], mib=nil)
      if id.nil?
        raise ArgumentError
      elsif id.respond_to? :to_str
        super(make_integers(id.to_str.split(".")))
      else
        super(make_integers(id.to_ary))
      end
      @mib = mib
    rescue ArgumentError
      raise ArgumentError, "#{id.inspect}:#{id.class} not a valid object ID"
    end

### Public Instance Methods

asn1_type() click to toggle source

    # File lib/snmp/varbind.rb, line 144
    def asn1_type
      "OBJECT IDENTIFIER"
    end

encode() click to toggle source

    # File lib/snmp/varbind.rb, line 197
    def encode
      encode_object_id(self)
    end

index(parent_tree) click to toggle source

Returns an index based on the difference between this ObjectId and the provided parent ObjectId.

For example, ObjectId.new("1.3.6.1.5").index("1.3.6.1") returns an ObjectId of "5".

    # File lib/snmp/varbind.rb, line 224
    def index(parent_tree)
      parent_tree = make_object_id(parent_tree)
      if not subtree_of?(parent_tree)
        raise ArgumentError, "#{self.to_s} not a subtree of #{parent_tree.to_s}"
      elsif self.length == parent_tree.length
        raise ArgumentError, "OIDs are the same"
      else
        ObjectId.new(self[parent_tree.length..-1])
      end
    end

inspect() click to toggle source

    # File lib/snmp/varbind.rb, line 193
    def inspect
      "[#{to_str}]"
    end

subtree_of?(parent_tree) click to toggle source

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".

    # File lib/snmp/varbind.rb, line 205
    def subtree_of?(parent_tree)
      parent_tree = make_object_id(parent_tree)
      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_oid() click to toggle source

    # File lib/snmp/varbind.rb, line 177
    def to_oid
      self
    end

to_s() click to toggle source

    # File lib/snmp/varbind.rb, line 181
    def to_s
      if @mib
        @mib.name(self)
      else
        to_str
      end
    end

to_str() click to toggle source

    # File lib/snmp/varbind.rb, line 189
    def to_str
      self.join('.')
    end

to_varbind() click to toggle source

    # File lib/snmp/varbind.rb, line 173
    def to_varbind
      VarBind.new(self, Null)
    end

with_mib(mib) click to toggle source

Adds MIB information to this object_id for use with to_s.

    # File lib/snmp/varbind.rb, line 168
    def with_mib(mib)
      @mib = mib
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.