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
#[], #count_all_elements, #index_of, #reset!
Constructor Details
#initialize(*args) ⇒ Pusher
Returns a new instance of Pusher.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/qfill/pusher.rb', line 48
def initialize(*args)
super(*args)
with_ratio = queues.map(&:ratio).compact
ratio_to_split = (1 - with_ratio.sum)
num_without_ratio = queues.length - with_ratio.length
if num_without_ratio.positive? && ratio_to_split <= 1
equal_portion = ratio_to_split / num_without_ratio
queues.each do |queue|
next unless queue.ratio.nil?
queue.tap do |q|
q.ratio = equal_portion
end
end
end
end
|
Class Method Details
.from_array_of_hashes(array_of_hashes = []) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/qfill/pusher.rb', line 82
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
68
69
70
|
# File 'lib/qfill/pusher.rb', line 68
def current_list
queues[current_index]
end
|
#each(&block) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/qfill/pusher.rb', line 97
def each(&block)
return enum_for(:each) unless block
queues.each(&block)
end
|
#more_to_fill? ⇒ Boolean
89
90
91
|
# File 'lib/qfill/pusher.rb', line 89
def more_to_fill?
!queues.reject(&:is_full?).empty?
end
|
#next_to_fill ⇒ Object
93
94
95
|
# File 'lib/qfill/pusher.rb', line 93
def next_to_fill
queues.reject(&:is_full?).first
end
|
#set_next_as_current! ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/qfill/pusher.rb', line 72
def set_next_as_current!
next_index = current_index + 1
if (next_index) == queues.length
reset!
else
self.current_index = next_index
end
end
|