class Irc::QueueRing

Public Class Methods

new() click to toggle source

A QueueRing is implemented as an array with elements in the form

chan, [message1, message2, …

Note that the channel chan has no actual bearing with the channels to which messages will be sent

# File lib/rbot/ircsocket.rb, line 92
def initialize
  @storage = Array.new
  @last_idx = -1
end

Public Instance Methods

clear() click to toggle source
# File lib/rbot/ircsocket.rb, line 97
def clear
  @storage.clear
  @last_idx = -1
end
empty?() click to toggle source
# File lib/rbot/ircsocket.rb, line 111
def empty?
  @storage.empty?
end
length() click to toggle source
# File lib/rbot/ircsocket.rb, line 102
def length
  len = 0
  @storage.each {|c|
    len += c[1].size
  }
  return len
end
Also aliased as: size
next() click to toggle source
# File lib/rbot/ircsocket.rb, line 126
def next
  if empty?
    warning "trying to access empty ring"
    return nil
  end
  save_idx = @last_idx
  @last_idx = (@last_idx + 1) % @storage.size
  mess = @storage[@last_idx][1].first
  @last_idx = save_idx
  return mess
end
push(mess, chan) click to toggle source
# File lib/rbot/ircsocket.rb, line 115
def push(mess, chan)
  cmess = @storage.assoc(chan)
  if cmess
    idx = @storage.index(cmess)
    cmess[1] << mess
    @storage[idx] = cmess
  else
    @storage << [chan, [mess]]
  end
end
shift() click to toggle source
# File lib/rbot/ircsocket.rb, line 138
def shift
  if empty?
    warning "trying to access empty ring"
    return nil
  end
  @last_idx = (@last_idx + 1) % @storage.size
  mess = @storage[@last_idx][1].shift
  @storage.delete(@storage[@last_idx]) if @storage[@last_idx][1] == []
  return mess
end
size()
Alias for: length