Class: Velocity::Instance::Dictionary::AutocompleteSuggestionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/acceleration/velocity.rb

Overview

A simple wrapper for autocomplete suggestions

Created only by Dictionary#autocomplete_suggest. Note that the suggestions will already be in descending order by number of occurrences.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, suggestions = {}, xml = nil) ⇒ AutocompleteSuggestionSet

Create a new set of suggestions



1173
1174
1175
1176
1177
# File 'lib/acceleration/velocity.rb', line 1173

def initialize(query, suggestions = {}, xml = nil)
  @query = query
  @suggestions = suggestions
  @doc = xml
end

Instance Attribute Details

#docObject

The raw XML



1167
1168
1169
# File 'lib/acceleration/velocity.rb', line 1167

def doc
  @doc
end

#queryObject (readonly)

The original text to be autocompleted



1169
1170
1171
# File 'lib/acceleration/velocity.rb', line 1169

def query
  @query
end

#suggestionsObject (readonly)

The suggestions array



1171
1172
1173
# File 'lib/acceleration/velocity.rb', line 1171

def suggestions
  @suggestions
end

Class Method Details

.new_from_xml(xml) ⇒ Object

Create a new set of suggestions given some XML from Velocity



1180
1181
1182
1183
1184
1185
1186
# File 'lib/acceleration/velocity.rb', line 1180

def self.new_from_xml(xml)
  query = xml.xpath('/suggestions/@query').first.value
  suggestions = xml.xpath('/suggestions/suggestion').collect do |s|
    AutocompleteSuggestion.new_from_xml s
  end
  AutocompleteSuggestionSet.new(query, suggestions, xml)
end