Class: Tire::Suggest::Suggestion
- Inherits:
-
Object
- Object
- Tire::Suggest::Suggestion
- Defined in:
- lib/tire/suggest/suggestion.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #completion(value, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Suggestion
constructor
A new instance of Suggestion.
- #phrase(field, options = {}, &block) ⇒ Object
- #term(value, options = {}) ⇒ Object
- #text(value) ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Suggestion
Returns a new instance of Suggestion.
7 8 9 10 11 |
# File 'lib/tire/suggest/suggestion.rb', line 7 def initialize(name, &block) @name = name @value = {} block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/tire/suggest/suggestion.rb', line 5 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/tire/suggest/suggestion.rb', line 5 def value @value end |
Instance Method Details
#completion(value, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/tire/suggest/suggestion.rb', line 18 def completion(value, ={}) @value[:completion] = {:field => value}.update() self end |
#phrase(field, options = {}, &block) ⇒ Object
28 29 30 31 |
# File 'lib/tire/suggest/suggestion.rb', line 28 def phrase(field, ={}, &block) @value[:phrase] = PhraseSuggester.new(field, , &block).to_hash self end |
#term(value, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/tire/suggest/suggestion.rb', line 23 def term(value, ={}) @value[:term] = { :field => value }.update() self end |
#text(value) ⇒ Object
13 14 15 16 |
# File 'lib/tire/suggest/suggestion.rb', line 13 def text(value) @value[:text] = value self end |
#to_hash ⇒ Object
33 34 35 |
# File 'lib/tire/suggest/suggestion.rb', line 33 def to_hash {@name.to_sym => @value} end |
#to_json(options = {}) ⇒ Object
37 38 39 |
# File 'lib/tire/suggest/suggestion.rb', line 37 def to_json(={}) to_hash.to_json end |