Permalink
Browse files

Adding option to ignore certain characters

  • Loading branch information...
1 parent 4868504 commit b35e7a20dc03156ff43acda363fcd85d7dc1375f vincentchu committed Sep 15, 2011
Showing with 22 additions and 6 deletions.
  1. +15 −4 lib/fuzz_ball.rb
  2. +7 −2 spec/lib/fuzz_ball_spec.rb
View
@@ -4,10 +4,11 @@ class FuzzBall
include ArrayMethods
- attr_reader :files, :files_array
+ attr_reader :files, :files_array, :options
- def initialize(files)
- @files = files
+ def initialize(files, opts = {})
+ @options = opts
+ @files = files
@files_array = files.collect {|f| str2arr(f)}
@curr_alignment = []
@@ -56,7 +57,17 @@ def decimate_strings!(needle)
end
def str2arr( str )
- str.unpack("U*")
+ if options[:ignore]
+
+ regexp = options[:ignore].collect { |s|
+ Regexp.escape(s)
+ }.join("|")
+
+ regexp = Regexp.new("(#{regexp})")
+ str.gsub(regexp, "").unpack("U*")
+ else
+ str.unpack("U*")
+ end
end
def arr2str( arr )
@@ -9,12 +9,17 @@
describe "#initialize" do
it "should initialize with a list of files" do
- @fuzz.files.should == ["aaa", "bbb"]
+ @fuzz.files.should == ["aaa", "bbb"]
end
it "should convert the list of files into their array representations" do
@fuzz.files_array.should == ["aaa".unpack("U*"), "bbb".unpack("U*")]
end
+
+ it "should weed out characters that are designated to be ignored" do
+ fuzz = FuzzBall.new(["path/to/file.txt"], :ignore => %w(. /))
+ fuzz.files_array.should == ["pathtofiletxt".unpack("U*")]
+ end
end
describe "#search" do
@@ -52,7 +57,7 @@
end
describe "#smith_waterman" do
- it "should align the two strings" do
+ it "should align the two strings" do
@fuzz.send(:smith_waterman, [1,2,3], [2,3,4])
@fuzz.instance_eval { @curr_alignment }.should == [2, 1, 1, 0]
@fuzz.instance_eval { @curr_score }.should == 2.0

0 comments on commit b35e7a2

Please sign in to comment.