lib/picky/internals/indexed/categories.rb in picky-2.0.0 vs lib/picky/internals/indexed/categories.rb in picky-2.1.0
- old
+ new
@@ -65,11 +65,11 @@
end
# Gets all similar tokens and puts together the possible combinations
# for each found similar token.
#
def similar_possible_for token
- # Get as many similar tokens as necessary
+ # Get as many tokens as necessary
#
tokens = similar_tokens_for token
# possible combinations
#
inject_possible_for tokens
@@ -103,12 +103,16 @@
# Note: Returns [] if no categories matched (will produce no result).
# Returns nil if this token needs to be removed from the query.
# (Also none of the categories matched, but the ignore unassigned
# tokens option is true)
#
+ # TODO Could use Combinations class here and remove the inject.
+ #
def possible_for token, preselected_categories = nil
- possible = (preselected_categories || possible_categories(token)).map { |category| category.combination_for(token) }
- possible.compact!
+ possible = (preselected_categories || possible_categories(token)).inject([]) do |combinations, category|
+ combination = category.combination_for token
+ combination ? combinations << combination : combinations
+ end
# This is an optimization to mark tokens that are ignored.
#
return if ignore_unassigned_tokens && possible.empty?
possible # wrap in combinations
end
\ No newline at end of file