From de922de55b4c77294f8508ac71e4ff0082198461 Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 29 Dec 2015 12:51:47 +0700 Subject: [PATCH] #48 Fuzzily::String#normalize should not strip numbers --- lib/fuzzily/trigram.rb | 2 +- spec/fuzzily/trigram_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/fuzzily/trigram.rb b/lib/fuzzily/trigram.rb index f8424c3..58821bf 100644 --- a/lib/fuzzily/trigram.rb +++ b/lib/fuzzily/trigram.rb @@ -21,7 +21,7 @@ def scored_trigrams def normalize ActiveSupport::Multibyte::Chars.new(self). mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').downcase.to_s. - gsub(/[^a-z]/,' '). + gsub(/[^a-z\d]/,' '). gsub(/\s+/,'*'). gsub(/^/,'**'). gsub(/$/,'*') diff --git a/spec/fuzzily/trigram_spec.rb b/spec/fuzzily/trigram_spec.rb index 26bb0a1..16b6df7 100644 --- a/spec/fuzzily/trigram_spec.rb +++ b/spec/fuzzily/trigram_spec.rb @@ -5,7 +5,7 @@ def result(string) described_class.new(string).trigrams end - + it 'splits strings into trigrams' do result('Paris').should == %w(**p *pa par ari ris is*) end @@ -22,4 +22,8 @@ def result(string) # The final ess, sse, se* would be dupes. result('Besse-en-Chandesse').should == %w(**b *be bes ess sse se* e*e *en en* n*c *ch cha han and nde des) end + + it 'retain numbers' do + result('678 street').should == %w(**6 *67 678 78* 8*s *st str tre ree eet et*) + end end \ No newline at end of file