Class: Lita::Handlers::RoomQueue
- Inherits:
-
Object
- Object
- Lita::Handlers::RoomQueue
- Defined in:
- lib/lita/handlers/room_queue.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(student) ⇒ Object
- #clear! ⇒ Object
- #count ⇒ Object
- #include?(student) ⇒ Boolean
-
#initialize(name, redis) ⇒ RoomQueue
constructor
A new instance of RoomQueue.
- #next ⇒ Object
- #queue ⇒ Object
- #remove(student) ⇒ Object
Constructor Details
#initialize(name, redis) ⇒ RoomQueue
Returns a new instance of RoomQueue.
6 7 8 9 |
# File 'lib/lita/handlers/room_queue.rb', line 6 def initialize(name, redis) @name = name @redis = redis end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lita/handlers/room_queue.rb', line 4 def name @name end |
Instance Method Details
#add(student) ⇒ Object
24 25 26 |
# File 'lib/lita/handlers/room_queue.rb', line 24 def add(student) @redis.set(@name, self.queue.push(student)) end |
#clear! ⇒ Object
38 39 40 |
# File 'lib/lita/handlers/room_queue.rb', line 38 def clear! @redis.del(@name) end |
#count ⇒ Object
16 17 18 |
# File 'lib/lita/handlers/room_queue.rb', line 16 def count self.queue.length end |
#include?(student) ⇒ Boolean
20 21 22 |
# File 'lib/lita/handlers/room_queue.rb', line 20 def include?(student) self.queue.include?(student) end |
#next ⇒ Object
32 33 34 35 36 |
# File 'lib/lita/handlers/room_queue.rb', line 32 def next student = self.queue.shift @redis.set(@name, self.queue.reject { |x| x == student }) student end |
#queue ⇒ Object
11 12 13 14 |
# File 'lib/lita/handlers/room_queue.rb', line 11 def queue data = @redis.get(@name) data ? MultiJson.load(data) : [] end |
#remove(student) ⇒ Object
28 29 30 |
# File 'lib/lita/handlers/room_queue.rb', line 28 def remove(student) @redis.set(@name, self.queue.reject { |x| x == student }) end |