Class: Cdek::CitySuggestions

Inherits:
Object
  • Object
show all
Defined in:
lib/cdek/city_suggestions.rb

Overview

Builds normalized city suggestions for host application autocomplete UIs.

Constant Summary collapse

DEFAULT_COUNTRY_CODE =
"RU"
DEFAULT_LIMIT =
10
MIN_QUERY_LENGTH =
2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, client: Cdek.client, country_code: DEFAULT_COUNTRY_CODE, limit: DEFAULT_LIMIT) ⇒ CitySuggestions

Returns a new instance of CitySuggestions.



16
17
18
19
20
21
# File 'lib/cdek/city_suggestions.rb', line 16

def initialize(query, client: Cdek.client, country_code: DEFAULT_COUNTRY_CODE, limit: DEFAULT_LIMIT)
  @query = query
  @client = client
  @country_code = country_code
  @limit = limit
end

Class Method Details

.call(query, **options) ⇒ Object



11
12
13
# File 'lib/cdek/city_suggestions.rb', line 11

def call(query, **options)
  new(query, **options).call
end

Instance Method Details

#callObject



23
24
25
# File 'lib/cdek/city_suggestions.rb', line 23

def call
  normalized_query.length < MIN_QUERY_LENGTH ? [] : normalized_suggestions
end