lib/picky/query/allocations.rb in picky-4.12.4 vs lib/picky/query/allocations.rb in picky-4.12.5
- old
+ new
@@ -44,15 +44,48 @@
#
def reduce_to amount
@allocations = @allocations.shift amount
end
- # Removes combinations.
+ # Removes categories from allocations.
#
# Only those passed in are removed.
#
- def remove categories = []
+ def remove_categories categories = []
@allocations.each { |allocation| allocation.remove categories } unless categories.empty?
+ end
+
+ # Removes allocations.
+ #
+ # Only those passed in are removed.
+ #
+ # TODO Rewrite, speed up.
+ #
+ def remove_allocations qualifiers_array = []
+ return if qualifiers_array.empty?
+ @allocations.select! do |allocation|
+ allocation_qualifiers = allocation.combinations.to_qualifiers
+ next(false) if qualifiers_array.any? do |qualifiers|
+ allocation_qualifiers == qualifiers
+ end
+ allocation
+ end
+ end
+
+ # Keeps allocations.
+ #
+ # Only those passed in are kept.
+ #
+ # TODO Rewrite, speed up.
+ #
+ def keep_allocations qualifiers_array = []
+ return if qualifiers_array.empty?
+ @allocations.select! do |allocation|
+ allocation_qualifiers = allocation.combinations.to_qualifiers
+ next(true) if qualifiers_array.any? do |qualifiers|
+ allocation_qualifiers == qualifiers
+ end
+ end
end
# Returns the top amount ids.
#
def ids amount = 20
\ No newline at end of file