Class: Qfill::Pusher
Instance Attribute Summary
Attributes inherited from ListSet
Class Method Summary collapse
Instance Method Summary collapse
- #current_list ⇒ Object
-
#initialize(*args) ⇒ Pusher
constructor
A new instance of Pusher.
- #set_next_as_current! ⇒ Object
Methods inherited from ListSet
#[], #get_total_elements, #reset!
Constructor Details
#initialize(*args) ⇒ Pusher
Returns a new instance of Pusher.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/qfill/pusher.rb', line 43 def initialize(*args) super(*args) with_ratio = self.queues.map {|x| x.ratio}.compact ratio_to_split = (1 - with_ratio.inject(0, :+)) if ratio_to_split < 0 raise ArgumentError, "#{self.class}: mismatched ratios for queues #{with_ratio.join(' + ')} must not total more than 1" end num_without_ratio = self.queues.length - with_ratio.length if num_without_ratio > 0 && ratio_to_split < 1 equal_portion = ratio_to_split / num_without_ratio self.queues.each do |queue| if queue.ratio.nil? queue.tap do |q| q.ratio = equal_portion end end end end end |
Class Method Details
Instance Method Details
#current_list ⇒ Object
63 64 65 |
# File 'lib/qfill/pusher.rb', line 63 def current_list self.queues[self.current_index] end |
#set_next_as_current! ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/qfill/pusher.rb', line 67 def set_next_as_current! next_index = self.current_index + 1 if (next_index) == self.queues.length # If we have iterated through all the queues, then we reset self.reset! else self.current_index = next_index end end |