Class: Picky::Query::Combinations
- Defined in:
- lib/picky/query/combinations.rb
Overview
Combinations represent an ordered list of Combination s.
Combinations contain methods for calculating score (including the boost) and ids for each of its Combination s.
They are the core of an Allocation. An Allocation consists of a number of Combinations.
Instance Attribute Summary collapse
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
TODO.
-
#initialize(combinations = []) ⇒ Combinations
constructor
A new instance of Combinations.
-
#remove(categories = []) ⇒ Object
Filters the tokens and categories such that categories that are passed in, are removed.
-
#score ⇒ Object
Sums up the weights of the combinations.
- #to_qualifiers ⇒ Object
- #to_result ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(combinations = []) ⇒ Combinations
Returns a new instance of Combinations.
22 23 24 |
# File 'lib/picky/query/combinations.rb', line 22 def initialize combinations = [] @combinations = combinations end |
Instance Attribute Details
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
15 16 17 |
# File 'lib/picky/query/combinations.rb', line 15 def combinations @combinations end |
Instance Method Details
#each(&block) ⇒ Object
TODO
28 29 30 |
# File 'lib/picky/query/combinations.rb', line 28 def each &block @combinations.each &block end |
#remove(categories = []) ⇒ Object
Filters the tokens and categories such that categories that are passed in, are removed.
Note: This method is not totally independent of the calculate_ids one. Since identifiers are only nullified, we need to not include the ids that have an associated identifier that is nil.
47 48 49 50 51 |
# File 'lib/picky/query/combinations.rb', line 47 def remove categories = [] # TODO Do not use the name, but the category. # @combinations.reject! { |combination| categories.include?(combination.category_name) } end |
#score ⇒ Object
Sums up the weights of the combinations.
Note: Optimized sum(&:weight) away – ~3% improvement.
36 37 38 |
# File 'lib/picky/query/combinations.rb', line 36 def score @combinations.inject(0) { |total, combination| total + combination.weight } end |
#to_qualifiers ⇒ Object
59 60 61 |
# File 'lib/picky/query/combinations.rb', line 59 def to_qualifiers @combinations.map &:category_name end |
#to_result ⇒ Object
55 56 57 |
# File 'lib/picky/query/combinations.rb', line 55 def to_result @combinations.map &:to_result end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/picky/query/combinations.rb', line 65 def to_s @combinations.to_s end |