Module: Rubypostal::Wrapper

Extended by:
LibpostalWrapper
Defined in:
lib/rubypostal.rb

Class Method Summary collapse

Class Method Details

.expand_address(address) ⇒ Object



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

  # Setup options and initialize the count for expansions
  options = libpostal_get_default_options
  num_expansions_ptr = FFI::MemoryPointer.new(:size_t)

  # Call expand_address and get the result
  expansions_ptr = libpostal_expand_address(address, options, num_expansions_ptr)
  num_expansions = num_expansions_ptr.read(:size_t)

  # Manually read the array of strings
  expansions = num_expansions.times.map do |i|
    expansions_ptr.get_pointer(i * FFI.type_size(:pointer)).read_string
  end

  # Cleanup memory
  libpostal_expansion_array_destroy(expansions_ptr, num_expansions)

  expansions
end

.parse_address(address) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rubypostal.rb', line 11

def self.parse_address(address)
  options = default_options
  response = parse_address_with_options(address, options)
  results = extract_results(response)
  destroy_response(response)

  results
end