Class: OSPFv2::Hello::Neighbors

Inherits:
Object
  • Object
show all
Defined in:
lib/packet/hello.rb

Constant Summary collapse

Neighbor =
Class.new(OSPFv2::Id)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ Neighbors

Returns a new instance of Neighbors.



197
198
199
200
# File 'lib/packet/hello.rb', line 197

def initialize(arg=nil)
  @set = Set.new
  [arg].compact.flatten.each { |x| self + x }
end

Instance Attribute Details

#routersObject (readonly)

Returns the value of attribute routers.



196
197
198
# File 'lib/packet/hello.rb', line 196

def routers
  @routers
end

Instance Method Details

#+(id) ⇒ Object



201
202
203
# File 'lib/packet/hello.rb', line 201

def +(id)
  @set << neighbor(id)
end

#-(id) ⇒ Object



211
212
213
# File 'lib/packet/hello.rb', line 211

def -(id)
  @set.delete neighbor(id)
end

#[](val) ⇒ Object



217
218
219
# File 'lib/packet/hello.rb', line 217

def [](val)
  neighbors[val]
end

#encodeObject



214
215
216
# File 'lib/packet/hello.rb', line 214

def encode 
  ids.pack('N*')
end

#has?(id) ⇒ Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/packet/hello.rb', line 208

def has?(id)
  ids.include?(neighbor(id))
end

#neighborsObject Also known as: ids



204
205
206
# File 'lib/packet/hello.rb', line 204

def neighbors
  @set.collect.sort
end

#to_s_aryObject



220
221
222
# File 'lib/packet/hello.rb', line 220

def to_s_ary
  ids.collect { |id| Neighbor.new(id).to_ip  }
end