Class: Elastic::Results::ScoredCollection
- Includes:
- Enumerable
- Defined in:
- lib/elastic/results/scored_collection.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](_idx) ⇒ Object
- #count ⇒ Object
- #each(&_block) ⇒ Object
- #each_with_score(&_block) ⇒ Object
-
#initialize(_collection) ⇒ ScoredCollection
constructor
A new instance of ScoredCollection.
- #last ⇒ Object
- #map_with_score(&_block) ⇒ Object
- #traverse(&_block) ⇒ Object
Methods inherited from Base
Methods included from Support::Traversable
Constructor Details
#initialize(_collection) ⇒ ScoredCollection
Returns a new instance of ScoredCollection.
5 6 7 |
# File 'lib/elastic/results/scored_collection.rb', line 5 def initialize(_collection) @collection = _collection end |
Instance Method Details
#[](_idx) ⇒ Object
13 14 15 |
# File 'lib/elastic/results/scored_collection.rb', line 13 def [](_idx) @collection[_idx].try(:data) end |
#count ⇒ Object
9 10 11 |
# File 'lib/elastic/results/scored_collection.rb', line 9 def count @collection.count end |
#each(&_block) ⇒ Object
21 22 23 |
# File 'lib/elastic/results/scored_collection.rb', line 21 def each(&_block) @collection.map(&:data).each(&_block) end |
#each_with_score(&_block) ⇒ Object
25 26 27 |
# File 'lib/elastic/results/scored_collection.rb', line 25 def each_with_score(&_block) @collection.map { |sd| [sd.data, sd.score] }.each(&_block) end |
#last ⇒ Object
17 18 19 |
# File 'lib/elastic/results/scored_collection.rb', line 17 def last @collection.last.try(:data) end |
#map_with_score(&_block) ⇒ Object
29 30 31 32 33 |
# File 'lib/elastic/results/scored_collection.rb', line 29 def map_with_score(&_block) ScoredCollection.new( @collection.map { |sd| ScoredItem.new(_block.call(sd), sd.score) }.to_a ) end |
#traverse(&_block) ⇒ Object
35 36 37 38 |
# File 'lib/elastic/results/scored_collection.rb', line 35 def traverse(&_block) super @collection.each { |sd| sd.traverse(&_block) } end |