Class: Tire::Suggest::Suggestion

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/suggest/suggestion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tire/suggest/suggestion.rb', line 5

def name
  @name
end

#valueObject

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, options={})
  @value[:completion] = {:field => value}.update(options)
  self
end

#phrase(field, options = {}, &block) ⇒ Object



28
29
30
31
# File 'lib/tire/suggest/suggestion.rb', line 28

def phrase(field, options={}, &block)
  @value[:phrase] = PhraseSuggester.new(field, options, &block).to_hash
  self
end

#term(value, options = {}) ⇒ Object



23
24
25
26
# File 'lib/tire/suggest/suggestion.rb', line 23

def term(value, options={})
  @value[:term] = { :field => value }.update(options)
  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_hashObject



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(options={})
  to_hash.to_json
end