/libphonenumber-rb

Experimenting with Go-to-C-to-Ruby bindings 👩‍🔬

Primary LanguageRubyMIT LicenseMIT

Libphonenumber

experimentalBuild StatusCoverage Status

This gem is an experiment to use Go libphonenumber library in Ruby via C-extensions.

It will compile the go file in ext/libphonenumber/ into a standard shared object binary file (.so) exposing Go functions as C-style APIs. The gem will then rely on FFI to work with the API from the shared object.

This experiment was created to try and solve one specific problem: validation and formatting of phone numbers across services built in Go and Ruby.

Installation

Add this line to your application's Gemfile:

gem 'libphonenumber', github: "groyoh/libphonenumber-rb"

Usage

require "libphonenumber"

LibPhoneNumber.format_as_e164('+378886677', '') # => "+3780549886677"
LibPhoneNumber.format_as_national('+330618557497', 'FR') # => "0618557497"
LibPhoneNumber.get_region_code_from_phone_number('+330618557497') # => "FR"

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

As this is an experiment, any issue or PR will be rejected.

License

The gem is available as open source under the terms of the MIT License.