Sha256: c78afe3dd34ff6841b7933c695481a09a3016e350e5582033b5348d3a9585915
Contents?: true
Size: 717 Bytes
Versions: 7
Compression:
Stored size: 717 Bytes
Contents
# Some code borrowed from http://www.erikveen.dds.nl/levenshtein/doc/index.html require 'hintable_levenshtein' class Levenshtein def self.distance(s1, s2, threshold = nil) # If the arguments is nil s1 = s1.to_s unless s1 s2 = s2.to_s unless s2 s1, s2 = s2, s1 if s1.length > s2.length # s1 is the short one; s2 is the long one. if s2.length == 0 0.0 # Since s1.length < s2.length, s1 must be empty as well. else if threshold if (d = HintableLevenshtein.new.distance(s1, s2).to_f/s2.length) <= threshold d else nil end else HintableLevenshtein.new.distance(s1, s2).to_f/s2.length end end end end
Version data entries
7 entries across 7 versions & 2 rubygems