Class: Velocity::Instance::Dictionary::AutocompleteSuggestion

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

Overview

A simple wrapper for an autocomplete suggestion

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phrase, count = 0, xml = nil) ⇒ AutocompleteSuggestion

Create a new suggestion



1200
1201
1202
1203
1204
# File 'lib/acceleration/velocity.rb', line 1200

def initialize(phrase, count = 0, xml = nil)
  @phrase = phrase
  @count = count
  @doc = xml
end

Instance Attribute Details

#countObject (readonly)

The number of occurrences



1198
1199
1200
# File 'lib/acceleration/velocity.rb', line 1198

def count
  @count
end

#docObject

The xml



1194
1195
1196
# File 'lib/acceleration/velocity.rb', line 1194

def doc
  @doc
end

#phraseObject (readonly)

The phrase



1196
1197
1198
# File 'lib/acceleration/velocity.rb', line 1196

def phrase
  @phrase
end

Class Method Details

.new_from_xml(xml) ⇒ Object

Create a new suggestion given some XML from Velocity



1207
1208
1209
1210
1211
1212
1213
# File 'lib/acceleration/velocity.rb', line 1207

def self.new_from_xml(xml)
  AutocompleteSuggestion.new(
    xml.children.first.text,
    xml.attributes['count'].value.to_i,
    xml
  )
end

Instance Method Details

#to_sObject

This is really only ever going to be used as a string



1216
1217
1218
# File 'lib/acceleration/velocity.rb', line 1216

def to_s
  phrase
end