Class: Cdek::CityResolver
- Inherits:
-
Object
- Object
- Cdek::CityResolver
- Defined in:
- lib/cdek/city_resolver.rb
Overview
Resolves a human-readable city name to a CDEK city code.
This is intentionally small and API-backed: host applications can pass user-entered city names to the widget proxy without duplicating lookup logic or loading all delivery points for the whole country.
Constant Summary collapse
- DEFAULT_COUNTRY_CODES =
"RU"- CACHE_EXPIRES_IN =
43_200
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name, client: Cdek.client, country_codes: DEFAULT_COUNTRY_CODES, cache: default_cache) ⇒ CityResolver
constructor
A new instance of CityResolver.
Constructor Details
#initialize(name, client: Cdek.client, country_codes: DEFAULT_COUNTRY_CODES, cache: default_cache) ⇒ CityResolver
Returns a new instance of CityResolver.
19 20 21 22 23 24 |
# File 'lib/cdek/city_resolver.rb', line 19 def initialize(name, client: Cdek.client, country_codes: DEFAULT_COUNTRY_CODES, cache: default_cache) @name = name @client = client @country_codes = country_codes @cache = cache end |
Class Method Details
.call(name, **options) ⇒ Object
14 15 16 |
# File 'lib/cdek/city_resolver.rb', line 14 def call(name, **) new(name, **).call end |
Instance Method Details
#call ⇒ Object
26 27 28 |
# File 'lib/cdek/city_resolver.rb', line 26 def call normalized_name.empty? ? nil : cached_city_code end |