lib/picky/query/allocation.rb in picky-0.9.3 vs lib/picky/query/allocation.rb in picky-0.9.4

- old
+ new

@@ -2,17 +2,17 @@ # An allocation has a number of combinations: # [token, index] [other_token, other_index], ... # class Allocation - attr_reader :count, :ids, :score, :combinations - attr_accessor :result_type - + attr_reader :count, :ids, :score, :combinations, :result_type + # # - def initialize combinations + def initialize combinations, result_type @combinations = combinations + @result_type = result_type end def hash @combinations.hash end @@ -22,11 +22,11 @@ end # Scores its combinations and caches the result. # def calculate_score weights - @score || @score = @combinations.calculate_score(weights) + @score ||= @combinations.calculate_score(weights) end # Asks the combinations for the (intersected) ids. # def calculate_ids @@ -59,10 +59,10 @@ end # Transform the allocation into result form. # def to_result - [self.result_type, self.score, self.count, @combinations.to_result, self.ids] if count = self.count > 0 + [self.result_type, self.score, self.count, @combinations.to_result, self.ids] if self.count > 0 end # Json representation of this allocation. # # Note: Delegates to to_result. \ No newline at end of file