Class: Binpacker::WorkerQueue
- Inherits:
-
Object
- Object
- Binpacker::WorkerQueue
- Includes:
- Enumerable
- Defined in:
- lib/binpacker/worker_queue.rb
Instance Attribute Summary collapse
-
#worker_id ⇒ Object
readonly
Returns the value of attribute worker_id.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(worker_id, tests = []) ⇒ WorkerQueue
constructor
A new instance of WorkerQueue.
- #peek ⇒ Object
- #pop ⇒ Object
- #push(test) ⇒ Object
- #remaining ⇒ Object
- #size ⇒ Object
- #total_weight(timings) ⇒ Object
Constructor Details
#initialize(worker_id, tests = []) ⇒ WorkerQueue
Returns a new instance of WorkerQueue.
9 10 11 12 13 |
# File 'lib/binpacker/worker_queue.rb', line 9 def initialize(worker_id, tests = []) @worker_id = worker_id @tests = tests.dup @index = 0 end |
Instance Attribute Details
#worker_id ⇒ Object (readonly)
Returns the value of attribute worker_id.
7 8 9 |
# File 'lib/binpacker/worker_queue.rb', line 7 def worker_id @worker_id end |
Instance Method Details
#each(&block) ⇒ Object
47 48 49 |
# File 'lib/binpacker/worker_queue.rb', line 47 def each(&block) @tests[@index..].each(&block) end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/binpacker/worker_queue.rb', line 27 def empty? @index >= @tests.size end |
#peek ⇒ Object
22 23 24 25 |
# File 'lib/binpacker/worker_queue.rb', line 22 def peek return nil if empty? @tests[@index] end |
#pop ⇒ Object
15 16 17 18 19 20 |
# File 'lib/binpacker/worker_queue.rb', line 15 def pop return nil if empty? test = @tests[@index] @index += 1 test end |
#push(test) ⇒ Object
43 44 45 |
# File 'lib/binpacker/worker_queue.rb', line 43 def push(test) @tests << test end |
#remaining ⇒ Object
35 36 37 |
# File 'lib/binpacker/worker_queue.rb', line 35 def remaining @tests[@index..] || [] end |
#size ⇒ Object
31 32 33 |
# File 'lib/binpacker/worker_queue.rb', line 31 def size @tests.size - @index end |
#total_weight(timings) ⇒ Object
39 40 41 |
# File 'lib/binpacker/worker_queue.rb', line 39 def total_weight(timings) remaining.sum { |t| timings.fetch(t.key, Timing::DEFAULT_WEIGHT) } end |