Skip to content

Commit

Permalink
Fixing exact matches even more
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Dutro committed Feb 12, 2013
1 parent da4a42d commit dcaa5bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Expand Up @@ -17,8 +17,8 @@ def find_closest(goal_pattern)
nil
else
cache_key = TwitterCldr::Utils.compute_cache_key(goal_pattern)
pattern_cache[cache_key] ||= if @pattern_hash.include?(goal_pattern)
@pattern_hash[goal_pattern]
pattern_cache[cache_key] ||= if @pattern_hash.include?(goal_pattern.to_sym)
@pattern_hash[goal_pattern.to_sym]
else
rank(goal_pattern).min do |(p1, score1), (p2, score2)|
score1 <=> score2
Expand Down
Expand Up @@ -4,6 +4,8 @@
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'
require 'pry'
require 'pry-nav'

include TwitterCldr::Tokenizers

Expand Down Expand Up @@ -90,10 +92,10 @@

describe "#find_closest" do
it "returns an exact match if it exists" do
selector.find_closest("h").should == "h"
selector.find_closest("MMMd").should == "MMMd"
selector.find_closest("Hms").should == "Hms"
selector.find_closest("yQQQQ").should == "yQQQQ"
selector.find_closest("h").should == "h a"
selector.find_closest("MMMd").should == "MMM d"
selector.find_closest("Hms").should == "HH:mm:ss"
selector.find_closest("yQQQQ").should == "QQQQ y"
end

it "returns the next closest match (lowest score) if an exact match can't be found" do
Expand Down

0 comments on commit dcaa5bc

Please sign in to comment.