10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/helpers/geocoding_helper.rb', line 10
def parse_address(address_line)
return unless address_line
match = address_line.match(/^(\d+)-(.+)$/)
if match
apartment = match[1]
address_without_apartment = match[2].strip
else
apartment = nil
address_without_apartment = address_line
end
response = geocoder_response(address_without_apartment)
destructured_response(response, apartment)
rescue StandardError => e
Rails.logger.error "Failed to parse address: #{e.message}, address: #{address_line}"
{
address_line1: address_line,
address_line2: nil,
province_id: Province::QUEBEC_PROVINCE_ID,
city: nil,
postal_code: nil,
country_id: Country::CANADA_ID
}
end
|