Top Level Namespace
Instance Method Summary collapse
Instance Method Details
#dameraulevenshtein(seq1, seq2) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fuzzy-require.rb', line 1 def dameraulevenshtein(seq1, seq2) oneago = nil thisrow = (1..seq2.size).to_a + [0] seq1.size.times do |x| twoago, oneago, thisrow = oneago, thisrow, [0] * seq2.size + [x + 1] seq2.size.times do |y| delcost = oneago[y] + 1 addcost = thisrow[y - 1] + 1 subcost = oneago[y - 1] + ((seq1[x] != seq2[y]) ? 1 : 0) thisrow[y] = [delcost, addcost, subcost].min if (x > 0 and y > 0 and seq1[x] == seq2[y-1] and seq1[x-1] == seq2[y] and seq1[x] != seq2[y]) thisrow[y] = [thisrow[y], twoago[y-2] + 1].min end end end return thisrow[seq2.size - 1] end |
#fzzrqr(path = nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fuzzy-require.rb', line 19 def fzzrqr(path = nil) begin require path || $fzzrqr rescue LoadError => e $fzzrqr = Gem.path.map {|gp| Dir.new(File.join(gp,'gems')).to_a }.flatten.map {|x| x =~ /-\d+\.\d+\.\d+/; $` }.compact.sort_by {|x| dameraulevenshtein(path,x)}.first raise LoadError.new("Gem #{path} not found in path - closest match is `#{$fzzrqr}`\nCall fzzrqr without arguments to require #{$fzzrqr}") end end |