lib/picky/bundle.rb in picky-3.6.16 vs lib/picky/bundle.rb in picky-4.0.0pre1
- old
+ new
@@ -45,19 +45,17 @@
def initialize name, category, weights_strategy, partial_strategy, similarity_strategy, options = {}
@name = name
@category = category
- # TODO Tidy up a bit.
- #
- @key_format = options.delete :key_format
- @backend = options.delete :backend
-
@weights_strategy = weights_strategy
@partial_strategy = partial_strategy
@similarity_strategy = similarity_strategy
+ @key_format = options.delete :key_format
+ @backend = options.delete :backend
+
reset_backend
end
def identifier
:"#{category.identifier}:#{name}"
end
@@ -104,11 +102,11 @@
end
def empty_inverted
@inverted = @backend_inverted.empty
end
def empty_weights
- # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ # THINK about this. Perhaps the strategies should implement the backend methods?
#
@weights = @weights_strategy.saved?? @backend_weights.empty : @weights_strategy
end
def empty_similarity
@similarity = @backend_similarity.empty
@@ -124,10 +122,11 @@
#
# Note: Does not return itself.
#
def similar text
code = similarity_strategy.encoded text
- similar_codes = code && @similarity[code]
+ return [] unless code
+ similar_codes = @similarity[code]
if similar_codes.blank?
[] # Return a simple array.
else
similar_codes = similar_codes.dup
similar_codes.delete text
\ No newline at end of file