fuzzy 0.0.1 → 9000.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.swp
2
+ pkg
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source 'http://rubygems.org'
2
+ group :test do
3
+ gem 'rspec'
4
+ gem 'ruby-debug19'
5
+ end
2
6
 
3
7
  # Specify your gem's dependencies in fuzzy.gemspec
4
8
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fuzzy (0.0.1)
5
+ fuzzy-string-match
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ RubyInline (3.11.0)
11
+ ZenTest (~> 4.3)
12
+ ZenTest (4.6.2)
13
+ archive-tar-minitar (0.5.2)
14
+ columnize (0.3.4)
15
+ diff-lcs (1.1.3)
16
+ fuzzy-string-match (0.9.1)
17
+ RubyInline (>= 3.8.6)
18
+ linecache19 (0.5.12)
19
+ ruby_core_source (>= 0.1.4)
20
+ rspec (2.7.0)
21
+ rspec-core (~> 2.7.0)
22
+ rspec-expectations (~> 2.7.0)
23
+ rspec-mocks (~> 2.7.0)
24
+ rspec-core (2.7.1)
25
+ rspec-expectations (2.7.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.7.0)
28
+ ruby-debug-base19 (0.11.25)
29
+ columnize (>= 0.3.1)
30
+ linecache19 (>= 0.5.11)
31
+ ruby_core_source (>= 0.1.4)
32
+ ruby-debug19 (0.11.6)
33
+ columnize (>= 0.3.1)
34
+ linecache19 (>= 0.5.11)
35
+ ruby-debug-base19 (>= 0.11.19)
36
+ ruby_core_source (0.1.5)
37
+ archive-tar-minitar (>= 0.5.2)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ fuzzy!
44
+ rspec
45
+ ruby-debug19
data/fuzzy.gemspec CHANGED
@@ -5,9 +5,10 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Mark Burns"]
6
6
  gem.email = ["markthedeveloper@gmail.com"]
7
7
  gem.description = %q{Force ruby to use common sense instead of being so pedantic}
8
- gem.summary = %q{Fuzzy matching no method missing at last!!!!}
8
+ gem.summary = %q{Fuzzy matching for method missing - at last!!!!}
9
9
  gem.homepage = ""
10
10
 
11
+ gem.add_dependency "fuzzy-string-match"
11
12
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
13
  gem.files = `git ls-files`.split("\n")
13
14
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/fuzzy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fuzzy
2
- VERSION = "0.0.1"
2
+ VERSION = "9000.0.1"
3
3
  end
data/lib/fuzzy.rb CHANGED
@@ -1,5 +1,28 @@
1
1
  require "fuzzy/version"
2
+ require 'fuzzystringmatch'
2
3
 
3
- module Fuzzy
4
- # Your code goes here...
4
+ module FuzzyBear
5
+ def method_missing sym, *args, &block
6
+ chosen_method = fuzzy_match sym
7
+ puts "You requested #{sym}, our survey says: #{chosen_method}"
8
+ self.send chosen_method, *args, &block
9
+ end
10
+
11
+
12
+ def fuzzy_match requested_method
13
+ max = - (1.0/0)
14
+ matcher = FuzzyStringMatch::JaroWinkler.new.create :pure
15
+
16
+ chosen_method = nil
17
+ methods.each do |m|
18
+ distance = matcher.getDistance m.to_s, requested_method.to_s
19
+ if distance > max
20
+ max = distance
21
+ chosen_method = m.to_sym unless m.to_sym == :method_missing
22
+ end
23
+
24
+ end
25
+ chosen_method
26
+ end
27
+ # Your code goes here...
5
28
  end
data/lib/object.rb ADDED
File without changes
@@ -0,0 +1,46 @@
1
+ debugger
2
+ require './lib/fuzzy'
3
+
4
+
5
+ describe "Fuzzy" do
6
+ class BlankishSlate
7
+ instance_methods.each do |meth|
8
+ undef_method(meth) unless(meth.to_s =~ /\A__/ or %w(method_missing eval debugger send methods fuzzy_match).include? meth.to_s)
9
+ end
10
+ end
11
+
12
+ describe "#fuzzy_match" do
13
+ it "matches the nearest method name" do
14
+ class Egg < BlankishSlate #so we don't match things not in the tests
15
+ include FuzzyBear
16
+ def cheese
17
+ end
18
+
19
+ def shoe
20
+ end
21
+ end
22
+
23
+ Egg.new.fuzzy_match(:chase).should == :cheese
24
+ Egg.new.fuzzy_match(:shoes).should == :shoe
25
+ end
26
+ end
27
+
28
+ describe "#method_missing" do
29
+ it "calls the method you meant to call" do
30
+ class Horse < BlankishSlate
31
+ include FuzzyBear
32
+
33
+ def dog
34
+ "cat"
35
+ end
36
+
37
+ def spider
38
+ "fly"
39
+ end
40
+ end
41
+
42
+ Horse.new.god.should == "cat"
43
+ Horse.new.spyder.should == "fly"
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fuzzy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 9000.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Burns
@@ -11,8 +11,18 @@ bindir: bin
11
11
  cert_chain: []
12
12
 
13
13
  date: 2011-11-23 00:00:00 Z
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: fuzzy-string-match
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
16
26
  description: Force ruby to use common sense instead of being so pedantic
17
27
  email:
18
28
  - markthedeveloper@gmail.com
@@ -25,11 +35,14 @@ extra_rdoc_files: []
25
35
  files:
26
36
  - .gitignore
27
37
  - Gemfile
38
+ - Gemfile.lock
28
39
  - README.md
29
40
  - Rakefile
30
41
  - fuzzy.gemspec
31
42
  - lib/fuzzy.rb
32
43
  - lib/fuzzy/version.rb
44
+ - lib/object.rb
45
+ - spec/fuzzy_spec.rb
33
46
  homepage: ""
34
47
  licenses: []
35
48
 
@@ -56,6 +69,6 @@ rubyforge_project:
56
69
  rubygems_version: 1.8.11
57
70
  signing_key:
58
71
  specification_version: 3
59
- summary: Fuzzy matching no method missing at last!!!!
60
- test_files: []
61
-
72
+ summary: Fuzzy matching for method missing - at last!!!!
73
+ test_files:
74
+ - spec/fuzzy_spec.rb