Class: QuickQueue::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/quick_queue/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



5
6
7
# File 'lib/quick_queue/server.rb', line 5

def initialize(options = {})
  start(options)
end

Instance Method Details

#popObject



9
10
11
12
13
# File 'lib/quick_queue/server.rb', line 9

def pop
 @size = 0 if @queue.size <= 1
 return nil if @queue.empty?
 @queue.pop
end

#push(item) ⇒ Object



15
16
17
18
19
# File 'lib/quick_queue/server.rb', line 15

def push(item)
  # currently it only supports strings
  @queue.push item.to_s
  @size += 1
end

#sizeObject



21
22
23
# File 'lib/quick_queue/server.rb', line 21

def size 
  @size
end

#statusObject



25
26
27
28
29
30
31
32
33
# File 'lib/quick_queue/server.rb', line 25

def status
  status = "Current queue status: "
  if @size > 0
    percentage = (((@queue.length.to_f / @size.to_f) * 10000.0).floor / 100.0)
    status << "#{@queue.length} left of #{@size} (#{percentage}%)" 
  else
    status << "queue is empty"
  end
end