lib/fuzzily/trigram.rb in fuzzily-0.2.3 vs lib/fuzzily/trigram.rb in fuzzily-0.2.4
- old
+ new
@@ -2,10 +2,11 @@
require 'delegate'
module Fuzzily
class String < SimpleDelegator
def trigrams
+ return [] if __getobj__.nil?
normalized = self.normalize
number_of_trigrams = normalized.length - 3
trigrams = (0..number_of_trigrams).map { |index| normalized[index,3] }.uniq
end
@@ -16,10 +17,9 @@
protected
# Remove accents, downcase, replace spaces and word start with '*',
# return list of normalized words
def normalize
- # Iconv.iconv('ascii//translit//ignore', 'utf-8', self).first.
ActiveSupport::Multibyte::Chars.new(self).
mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').downcase.to_s.
gsub(/[^a-z]/,' ').
gsub(/\s+/,'*').
gsub(/^/,'**').