Class: Suggester::Handlers::Base
- Inherits:
-
Object
- Object
- Suggester::Handlers::Base
- Includes:
- Helpers::Refresh
- Defined in:
- lib/suggester/handlers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#unique_field_name ⇒ Object
name of the field in the data hash that should be unique.
Instance Method Summary collapse
-
#cache ⇒ Object
Returns an array of hashes with the following format: [ :search_term => <string>, :data => { <unique_field_name> => <anything> …other data to be returned } ] NOTE: must be sorted by :search_term.
-
#find(params) ⇒ Object
Returns an array of data hashes that begin with params.
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
-
#match(params) ⇒ Object
Returns an array of data hashes that are an exact match for params.
Methods included from Helpers::Refresh
#force_refresh!, #last_refreshed_at, #needs_refresh?, #refresh!, #refresh_interval, #refresh_interval=
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 |
# File 'lib/suggester/handlers/base.rb', line 17 def initialize(params = {}) @unique_field_name = params[:unique_field_name] || :display_string @refresh_interval = params.delete(:refresh_interval) @last_refreshed_at = Time.now @cache = build_cache end |
Instance Attribute Details
#unique_field_name ⇒ Object
name of the field in the data hash that should be unique
14 15 16 |
# File 'lib/suggester/handlers/base.rb', line 14 def unique_field_name @unique_field_name end |
Instance Method Details
#cache ⇒ Object
Returns an array of hashes with the following format:
[
:search_term => <string>,
:data => {
<unique_field_name> => <anything>
...other data to be returned
}
]
NOTE: must be sorted by :search_term
33 34 35 |
# File 'lib/suggester/handlers/base.rb', line 33 def cache @cache end |
#find(params) ⇒ Object
Returns an array of data hashes that begin with params
46 47 48 49 50 51 |
# File 'lib/suggester/handlers/base.rb', line 46 def find(params) query = params[:query].downcase limit = params[:limit] limit = limit.to_i unless limit.nil? results = find_begin_matches(query, limit, params) end |
#match(params) ⇒ Object
Returns an array of data hashes that are an exact match for params
38 39 40 41 42 43 |
# File 'lib/suggester/handlers/base.rb', line 38 def match(params) query = params[:query].downcase limit = params[:limit] limit = limit.to_i unless limit.nil? results = find_exact_matches(query, limit, params) end |