class Fuzzily::String
Public Instance Methods
scored_trigrams()
click to toggle source
# File lib/fuzzily/trigram.rb, line 13 def scored_trigrams trigrams.map { |t| [t, self.length] } end
trigrams()
click to toggle source
# File lib/fuzzily/trigram.rb, line 6 def trigrams return [] if __getobj__.blank? normalized = self.normalize number_of_trigrams = normalized.length - 3 trigrams = (0..number_of_trigrams).map { |index| normalized[index, 3] }.uniq end
Protected Instance Methods
normalize()
click to toggle source
Remove accents, downcase, replace spaces and word start with “*”, return list of normalized words
# File lib/fuzzily/trigram.rb, line 21 def normalize ActiveSupport::Multibyte::Chars.new(self.to_s) .mb_chars.unicode_normalize(:nfkd).to_s.downcase .gsub(/[^\x00-\x7F]/, "") .gsub(/[^a-z\d]/, " ") .gsub(/\s+/, "*") .gsub(/^/, "**") .gsub(/$/, "*") end