Class: Irc::QueueRing
- Inherits:
-
Object
- Object
- Irc::QueueRing
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/ircsocket.rb
Instance Method Summary (collapse)
- - (Object) clear
- - (Boolean) empty?
-
- (QueueRing) initialize
constructor
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. - - (Object) length (also: #size)
- - (Object) next
- - (Object) push(mess, chan)
- - (Object) shift
Constructor Details
- (QueueRing) initialize
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
92 93 94 95 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/ircsocket.rb', line 92 def initialize @storage = Array.new @last_idx = -1 end |
Instance Method Details
- (Object) clear
97 98 99 100 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/ircsocket.rb', line 97 def clear @storage.clear @last_idx = -1 end |
- (Boolean) empty?
111 112 113 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/ircsocket.rb', line 111 def empty? @storage.empty? end |
- (Object) length Also known as: size
102 103 104 105 106 107 108 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/ircsocket.rb', line 102 def length len = 0 @storage.each {|c| len += c[1].size } return len end |
- (Object) next
126 127 128 129 130 131 132 133 134 135 136 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Object) push(mess, chan)
115 116 117 118 119 120 121 122 123 124 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Object) shift
138 139 140 141 142 143 144 145 146 147 |
# File '/home/apoc/projects/ruby/rbot/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 |