module Amatch::StringMethods
This module can be mixed into ::String or its subclasses to mixin the similary methods directly.
Public Instance Methods
If called on a String, this string is used as
a Amatch::Hamming#pattern to
match against strings
. It returns a Hamming distance metric number between 0.0 for very
unsimilar strings and 1.0 for an exact match. strings
has to
be either a String or an Array of Strings. The
returned results
is either a Float or an Array of Floats
respectively.
static VALUE rb_str_hamming_similar(VALUE self, VALUE strings) { VALUE amatch = rb_Hamming_new(rb_cHamming, self); return rb_Hamming_similar(amatch, strings); }
If called on a String, this string is used as
a Amatch::Jaro#pattern to match
against strings
. It returns a Jaro
metric number between 0.0 for very unsimilar strings and 1.0 for an exact
match. strings
has to be either a String or an Array of Strings. The returned
results
is either a Float or an Array of Floats respectively.
static VALUE rb_str_jaro_similar(VALUE self, VALUE strings) { VALUE amatch = rb_Jaro_new(rb_cJaro, self); return rb_Jaro_match(amatch, strings); }
If called on a String, this string is used as
a Amatch::JaroWinkler#pattern to
match against strings
. It returns a Jaro-Winkler metric number
between 0.0 for very unsimilar strings and 1.0 for an exact match.
strings
has to be either a String
or an Array of Strings. The returned results
are either a
Float or an Array of Floats respectively.
static VALUE rb_str_jarowinkler_similar(VALUE self, VALUE strings) { VALUE amatch = rb_JaroWinkler_new(rb_cJaro, self); return rb_JaroWinkler_match(amatch, strings); }
If called on a String, this string is used as
a Amatch::Levenshtein#pattern to
match against strings
. It returns a Levenshtein distance metric number between 0.0
for very unsimilar strings and 1.0 for an exact match. strings
has to be either a String or an Array of
Strings. The returned results
is either a Float or an Array of
Floats respectively.
static VALUE rb_str_levenshtein_similar(VALUE self, VALUE strings) { VALUE amatch = rb_Levenshtein_new(rb_cLevenshtein, self); return rb_Levenshtein_similar(amatch, strings); }
If called on a String, this string is used as
a Amatch::LongestSubsequence#pattern
to match against strings
. It returns a longest subsequence
distance metric number between 0.0 for very unsimilar strings and 1.0 for
an exact match. strings
has to be either a String or an Array of Strings. The returned
results
is either a Float or an Array of Floats respectively.
static VALUE rb_str_longest_subsequence_similar(VALUE self, VALUE strings) { VALUE amatch = rb_LongestSubsequence_new(rb_cLongestSubsequence, self); return rb_LongestSubsequence_similar(amatch, strings); }
If called on a String, this string is used as
a Amatch::LongestSubstring#pattern
to match against strings
. It returns a longest substring
distance metric number between 0.0 for very unsimilar strings and 1.0 for
an exact match. strings
has to be either a String or an Array of Strings. The returned
results
is either a Float or an Array of Floats respectively.
static VALUE rb_str_longest_substring_similar(VALUE self, VALUE strings) { VALUE amatch = rb_LongestSubstring_new(rb_cLongestSubstring, self); return rb_LongestSubstring_similar(amatch, strings); }
If called on a String, this string is used as
a Amatch::PairDistance#pattern
to match against strings
using /s+/ as the tokenizing regular
expression. It returns a pair distance metric number between 0.0 for very
unsimilar strings and 1.0 for an exact match. strings
has to
be either a String or an Array of Strings.
The returned results
is either a Float or an Array of Floats
respectively.
static VALUE rb_str_pair_distance_similar(int argc, VALUE *argv, VALUE self) { VALUE amatch, string, regexp = Qnil; rb_scan_args(argc, argv, "11", &string, ®exp); amatch = rb_PairDistance_new(rb_cPairDistance, self); if (NIL_P(regexp)) { return rb_PairDistance_match(1, &string, amatch); } else { VALUE *args = alloca(2); args[0] = string; args[1] = regexp; return rb_PairDistance_match(2, args, amatch); } }