Skip to content

Commit

Permalink
first passing proper spec
Browse files Browse the repository at this point in the history
  • Loading branch information
markburns committed Nov 23, 2011
1 parent 91893c1 commit 7bfb3d7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source 'http://rubygems.org'
group :test do
gem 'rspec'
gem 'ruby-debug19'
end

# Specify your gem's dependencies in fuzzy.gemspec
gemspec
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
PATH
remote: .
specs:
fuzzy (0.0.1)
fuzzy-string-match

GEM
remote: http://rubygems.org/
specs:
RubyInline (3.11.0)
ZenTest (~> 4.3)
ZenTest (4.6.2)
archive-tar-minitar (0.5.2)
columnize (0.3.4)
diff-lcs (1.1.3)
fuzzy-string-match (0.9.1)
RubyInline (>= 3.8.6)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)

PLATFORMS
ruby

DEPENDENCIES
fuzzy!
rspec
ruby-debug19
3 changes: 2 additions & 1 deletion fuzzy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Gem::Specification.new do |gem|
gem.authors = ["Mark Burns"]
gem.email = ["markthedeveloper@gmail.com"]
gem.description = %q{Force ruby to use common sense instead of being so pedantic}
gem.summary = %q{Fuzzy matching no method missing at last!!!!}
gem.summary = %q{Fuzzy matching for method missing - at last!!!!}
gem.homepage = ""

gem.add_dependency "fuzzy-string-match"
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
21 changes: 19 additions & 2 deletions lib/object.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
require 'fuzzystringmatch'




class Object
def fuzzy_match meth
:cheese
def fuzzy_match requested_method
max = - (1.0/0)
matcher = FuzzyStringMatch::JaroWinkler.new.create :pure

chosen_method = nil

methods.each do |m|
distance = matcher.getDistance m.to_s, requested_method.to_s
if distance > max
max = distance
chosen_method = m.to_sym
end
end
chosen_method
end
end
3 changes: 3 additions & 0 deletions spec/fuzzy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
describe "Fuzzy" do
it "uses a fuzzy match algorithm to get the nearest matching method name" do
class Egg
instance_methods.each { |meth|
undef_method(meth) unless meth.to_s =~ /\A__/ or %w(methods fuzzy_match).include? meth.to_s
}
def cheese

end
Expand Down

0 comments on commit 7bfb3d7

Please sign in to comment.