Class: AtlasEngine::AddressValidation::Es::CandidateSelector

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
LogHelper
Defined in:
app/models/atlas_engine/address_validation/es/candidate_selector.rb

Instance Method Summary collapse

Methods included from LogHelper

#log_error, #log_info, #log_warn

Constructor Details

#initialize(datastore:, address:) ⇒ CandidateSelector

Returns a new instance of CandidateSelector.



12
13
14
15
# File 'app/models/atlas_engine/address_validation/es/candidate_selector.rb', line 12

def initialize(datastore:, address:)
  @datastore = T.let(datastore, DatastoreBase)
  @address = T.let(address, AbstractAddress)
end

Instance Method Details

#best_candidateObject



25
26
27
28
29
30
31
32
33
# File 'app/models/atlas_engine/address_validation/es/candidate_selector.rb', line 25

def best_candidate
  street_sequences_future = datastore.fetch_street_sequences_async
  city_sequences_future = datastore.fetch_city_sequence_async
  sorted_candidates.first
ensure
  # We want our futures to complete even when we do not consume their value.
  street_sequences_future&.wait!
  city_sequences_future&.wait!
end

#best_candidate_asyncObject



18
19
20
21
22
# File 'app/models/atlas_engine/address_validation/es/candidate_selector.rb', line 18

def best_candidate_async
  Concurrent::Promises.future do
    best_candidate
  end
end