Class: Tire::Search::Multi::Results
- Inherits:
-
Object
- Object
- Tire::Search::Multi::Results
- Includes:
- Enumerable
- Defined in:
- lib/tire/multi_search.rb
Overview
Wraps the search result sets for Tire::Multi::Search
Instance Method Summary collapse
-
#[](name) ⇒ Object
Return a specific result sets.
- #each(&block) ⇒ Object
- #each_pair(&block) ⇒ Object
-
#initialize(searches, results) ⇒ Results
constructor
A new instance of Results.
- #size ⇒ Object
-
#to_hash ⇒ Object
Returns the multi-search result sets as a Hash with the search name as key and the results as value.
Constructor Details
#initialize(searches, results) ⇒ Results
Returns a new instance of Results.
45 46 47 48 49 50 51 |
# File 'lib/tire/multi_search.rb', line 45 def initialize(searches, results) @searches = searches @results = results @collection = @results.zip(@searches.to_a).map do |results, search| Tire::Results::Collection.new(results, search.) end end |
Instance Method Details
#[](name) ⇒ Object
Return a specific result sets
54 55 56 57 58 |
# File 'lib/tire/multi_search.rb', line 54 def [] name if index = @searches.names.index(name) @collection[ index ] end end |
#each(&block) ⇒ Object
60 61 62 |
# File 'lib/tire/multi_search.rb', line 60 def each(&block) @collection.each(&block) end |
#each_pair(&block) ⇒ Object
64 65 66 |
# File 'lib/tire/multi_search.rb', line 64 def each_pair(&block) @searches.names.zip(@collection).each(&block) end |
#size ⇒ Object
68 69 70 |
# File 'lib/tire/multi_search.rb', line 68 def size @results.size end |
#to_hash ⇒ Object
Returns the multi-search result sets as a Hash with the search name as key and the results as value.
75 76 77 78 79 |
# File 'lib/tire/multi_search.rb', line 75 def to_hash result = {} each_pair { |name,results| result[name] = results } result end |