Class: Picky::Query::Combination::Or
- Inherits:
-
Picky::Query::Combination
- Object
- Picky::Query::Combination
- Picky::Query::Combination::Or
- Defined in:
- lib/picky/query/combination/or.rb
Overview
Pretends to be a combination.
TODO Rework completely and document.
Instance Attribute Summary
Attributes inherited from Picky::Query::Combination
Instance Method Summary collapse
-
#category_name ⇒ Object
Returns the combination’s category name.
- #identifier ⇒ Object
-
#ids ⇒ Object
Returns an array of ids from its combinations.
-
#initialize(combinations) ⇒ Or
constructor
A new instance of Or.
- #to_result ⇒ Object
-
#weight ⇒ Object
Returns the total (?) weight of its combinations.
Methods inherited from Picky::Query::Combination
Constructor Details
#initialize(combinations) ⇒ Or
Returns a new instance of Or.
13 14 15 |
# File 'lib/picky/query/combination/or.rb', line 13 def initialize combinations @combinations = combinations end |
Instance Method Details
#category_name ⇒ Object
Returns the combination’s category name. Used in boosting.
20 21 22 |
# File 'lib/picky/query/combination/or.rb', line 20 def category_name @category_name ||= @combinations.map(&:category_name).join('|').intern end |
#identifier ⇒ Object
44 45 46 |
# File 'lib/picky/query/combination/or.rb', line 44 def identifier @identifier ||= "#{@combinations.map(&:bundle).map(&:identifier).join('|')}:inverted:#{token.text}" end |
#ids ⇒ Object
Returns an array of ids from its combinations.
Note: Caching is most of the time useful.
38 39 40 41 42 |
# File 'lib/picky/query/combination/or.rb', line 38 def ids @ids ||= @combinations.inject([]) do |total, combination| total + combination.ids end.uniq end |
#to_result ⇒ Object
48 49 50 51 |
# File 'lib/picky/query/combination/or.rb', line 48 def to_result results = @combinations.map &:to_result [*@combinations.map(&:to_result).transpose.map! { |thing| thing.join('|') }] end |
#weight ⇒ Object
Returns the total (?) weight of its combinations.
Note: Caching is most of the time useful.
28 29 30 31 32 |
# File 'lib/picky/query/combination/or.rb', line 28 def weight @weight ||= @combinations.inject(0) do |sum, combination| sum + combination.weight end end |