Class: Inch::Utils::WeightedList
- Inherits:
-
Object
- Object
- Inch::Utils::WeightedList
- Defined in:
- lib/inch/utils/weighted_list.rb
Instance Method Summary collapse
-
#initialize(list_of_lists, counts) ⇒ WeightedList
constructor
Trims down a list of object lists to given sizes.
- #to_a ⇒ Array
Constructor Details
#initialize(list_of_lists, counts) ⇒ WeightedList
Trims down a list of object lists to given sizes. If there are not enough objects in any particular tier, they are filled up from the tier below/above.
This means there should be 4 :Bs, 8 :Cs, and 8 :Us in the resulting list. But we only have 2 :Bs, so the result is filled up with :Us:
WeightedList.new(list, counts).to_a
# => [
[:B1, :B2],
[:C1, :C2, :C3, :C4, :C5, :C6, :C7, :C8],
[:U1, :U2, :U3, :U4, :U5, :U6, :U7, :U8, :U9, :U10]
]
30 31 32 33 34 |
# File 'lib/inch/utils/weighted_list.rb', line 30 def initialize(list_of_lists, counts) @original = list_of_lists @max_counts = counts compute_list end |
Instance Method Details
#to_a ⇒ Array
37 38 39 |
# File 'lib/inch/utils/weighted_list.rb', line 37 def to_a @list end |