Class: QuickQueue::Server
- Inherits:
-
Object
- Object
- QuickQueue::Server
- Defined in:
- lib/quick_queue/server.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #pop ⇒ Object
- #push(item) ⇒ Object
- #size ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
5 6 7 |
# File 'lib/quick_queue/server.rb', line 5 def initialize( = {}) start() end |
Instance Method Details
#pop ⇒ Object
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 |
#size ⇒ Object
21 22 23 |
# File 'lib/quick_queue/server.rb', line 21 def size @size end |
#status ⇒ Object
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 |