Class: Lita::Handlers::RoomQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/handlers/room_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#countObject



16
17
18
# File 'lib/lita/handlers/room_queue.rb', line 16

def count
  self.queue.length
end

#include?(student) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/lita/handlers/room_queue.rb', line 20

def include?(student)
  self.queue.include?(student)
end

#nextObject



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

#queueObject



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