tonytonyjan / jaro_winkler

Ruby & C implementation of Jaro-Winkler distance algorithm which supports UTF-8 string.
MIT License
192 stars 29 forks source link

WIP: Enforce pure ruby version #21

Closed lwille closed 5 years ago

lwille commented 5 years ago

I was looking for a way to select the pure ruby version, as there may be circumstances where we can't afford to compile the native extension (missing libraries and headers) and don't need the performance of a native extension.

tonytonyjan commented 5 years ago

For your case, you can install the gem with --platform flag, and require 'jaro_winkler/jaro_winkler_pure', for example:

$ gem install --platform java jaro_winkler
Successfully installed jaro_winkler-1.5.1-universal-java-10
1 gem installed
$ ruby -r jaro_winkler/jaro_winkler_pure -e 'puts JaroWinkler.distance "lwille", "lwi11e"'
0.8444444444444443

It works in docker image ruby:2.5.0-alpine3.7, which has no built-in building environment:

$ docker run --rm ruby:2.5.0-alpine3.7 sh -c '\
  gem install --platform java jaro_winkler > /dev/null && \
  ruby -r jaro_winkler/jaro_winkler_pure -e \
  "puts JaroWinkler.distance %q{lwille}, %{lwi11e}"'
0.8444444444444443
lwille commented 5 years ago

That's a great solution if you control how it's required. I'm using it as a dependency of rubocop.

I managed to work around it, so I'm not super keen on getting this patch merged.