20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/rubypostal.rb', line 20
def self.expand_address(address)
raise "Libpostal setup failed" unless libpostal_setup && libpostal_setup_language_classifier
options = libpostal_get_default_options
num_expansions_ptr = FFI::MemoryPointer.new(:size_t)
expansions_ptr = libpostal_expand_address(address, options, num_expansions_ptr)
num_expansions = num_expansions_ptr.read(:size_t)
expansions = num_expansions.times.map do |i|
expansions_ptr.get_pointer(i * FFI.type_size(:pointer)).read_string
end
libpostal_expansion_array_destroy(expansions_ptr, num_expansions)
expansions
end
|