Class: Tire::Results::Suggestions
- Inherits:
-
Object
- Object
- Tire::Results::Suggestions
- Includes:
- Enumerable
- Defined in:
- lib/tire/results/suggestions.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #error ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(response, options = {}) ⇒ Suggestions
constructor
A new instance of Suggestions.
- #keys ⇒ Object
- #options(suggestion = :all) ⇒ Object
- #payloads(suggestion = :all) ⇒ Object
- #results ⇒ Object
- #size ⇒ Object
- #success? ⇒ Boolean
- #texts(suggestion = :all) ⇒ Object
Constructor Details
#initialize(response, options = {}) ⇒ Suggestions
Returns a new instance of Suggestions.
7 8 9 10 11 12 |
# File 'lib/tire/results/suggestions.rb', line 7 def initialize(response, ={}) @response = response @options = @shards_info ||= @response.delete '_shards' @keys ||= @response.keys end |
Instance Method Details
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/tire/results/suggestions.rb', line 23 def each(&block) results.each(&block) end |
#error ⇒ Object
55 56 57 |
# File 'lib/tire/results/suggestions.rb', line 55 def error @response['error'] end |
#failure? ⇒ Boolean
63 64 65 |
# File 'lib/tire/results/suggestions.rb', line 63 def failure? ! success? end |
#keys ⇒ Object
19 20 21 |
# File 'lib/tire/results/suggestions.rb', line 19 def keys @keys end |
#options(suggestion = :all) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/tire/results/suggestions.rb', line 31 def (suggestion=:all) if suggestion == :all results.map {|k,v| v.map{|s| s['options']}}.flatten else results[suggestion.to_s].map{|s| s['options']}.flatten end end |
#payloads(suggestion = :all) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tire/results/suggestions.rb', line 47 def payloads(suggestion=:all) if suggestion == :all results.map {|k,v| v.map{|s| s['options'].map {|o| o['payload']}}}.flatten else results[suggestion.to_s].map{|s| s['options'].map {|o| o['payload']}}.flatten end end |
#results ⇒ Object
14 15 16 17 |
# File 'lib/tire/results/suggestions.rb', line 14 def results return [] if failure? @results ||= @response end |
#size ⇒ Object
27 28 29 |
# File 'lib/tire/results/suggestions.rb', line 27 def size results.size end |
#success? ⇒ Boolean
59 60 61 |
# File 'lib/tire/results/suggestions.rb', line 59 def success? error.to_s.empty? end |
#texts(suggestion = :all) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/tire/results/suggestions.rb', line 39 def texts(suggestion=:all) if suggestion == :all results.map {|k,v| v.map{|s| s['options'].map {|o| o['text']}}}.flatten else results[suggestion.to_s].map{|s| s['options'].map {|o| o['text']}}.flatten end end |