Class: Qfill::Pusher
Instance Attribute Summary
Attributes inherited from ListSet
#current_index, #queues
Class Method Summary
collapse
Instance Method Summary
collapse
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
.from_array_of_hashes(array_of_hashes = []) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/qfill/pusher.rb', line 77
def self.from_array_of_hashes(array_of_hashes = [])
args = array_of_hashes.map do |hash|
Qfill::Result.new(hash)
end
Qfill::Pusher.new(*args)
end
|
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
|
#more_to_fill? ⇒ Boolean
84
85
86
|
# File 'lib/qfill/pusher.rb', line 84
def more_to_fill?
!self.queues.select {|x| !x.is_full?}.empty?
end
|
#next_to_fill ⇒ Object
88
89
90
|
# File 'lib/qfill/pusher.rb', line 88
def next_to_fill
self.queues.select {|x| !x.is_full?}.first
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
self.reset!
else
self.current_index = next_index
end
end
|