Class: Velocity::Instance::Dictionary::AutocompleteSuggestionSet
- Inherits:
-
Object
- Object
- Velocity::Instance::Dictionary::AutocompleteSuggestionSet
- 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
-
#doc ⇒ Object
The raw XML.
-
#query ⇒ Object
readonly
The original text to be autocompleted.
-
#suggestions ⇒ Object
readonly
The suggestions array.
Class Method Summary collapse
-
.new_from_xml(xml) ⇒ Object
Create a new set of suggestions given some XML from Velocity.
Instance Method Summary collapse
-
#initialize(query, suggestions = {}, xml = nil) ⇒ AutocompleteSuggestionSet
constructor
Create a new set of suggestions.
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
#doc ⇒ Object
The raw XML
1167 1168 1169 |
# File 'lib/acceleration/velocity.rb', line 1167 def doc @doc end |
#query ⇒ Object (readonly)
The original text to be autocompleted
1169 1170 1171 |
# File 'lib/acceleration/velocity.rb', line 1169 def query @query end |
#suggestions ⇒ Object (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 |