Class: Tire::Suggest::MultiSuggestion

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ MultiSuggestion

Returns a new instance of MultiSuggestion.



78
79
80
81
# File 'lib/tire/suggest/suggestion.rb', line 78

def initialize(&block)
  @value = {}
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Instance Attribute Details

#suggestionsObject

Returns the value of attribute suggestions.



76
77
78
# File 'lib/tire/suggest/suggestion.rb', line 76

def suggestions
  @suggestions
end

Instance Method Details

#suggestion(name, &block) ⇒ Object



88
89
90
91
92
# File 'lib/tire/suggest/suggestion.rb', line 88

def suggestion(name, &block)
  @suggestions ||= {}
  @suggestions.update Suggestion.new(name, &block).to_hash
  self
end

#text(value) ⇒ Object



83
84
85
86
# File 'lib/tire/suggest/suggestion.rb', line 83

def text(value)
  @global_text = value
  self
end

#to_hashObject



94
95
96
97
98
# File 'lib/tire/suggest/suggestion.rb', line 94

def to_hash
  @value.update @suggestions
  @value[:text] = @global_text if @global_text
  @value
end

#to_json(options = {}) ⇒ Object



100
101
102
# File 'lib/tire/suggest/suggestion.rb', line 100

def to_json(options={})
  to_hash.to_json
end