close_enough 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/close_enough/extensions.rb +35 -0
  2. metadata +3 -2
@@ -0,0 +1,35 @@
1
+ module CloseEnough
2
+ module Extensions
3
+ module ClassMethods
4
+
5
+ end
6
+
7
+ module InstanceMethods
8
+ private
9
+
10
+ def nearest_method(name)
11
+ dl = DamerauLevenshtein
12
+ ms = methods.map(&:to_s)
13
+ meth = ms.min_by {|possible| dl.distance(name.to_s, possible)}
14
+ unless dl.distance(name.to_s, meth) < 3
15
+ return false
16
+ else
17
+ warn "[CloseEnough] #{name.to_s} not found, using #{meth.to_s} instead"
18
+ return meth
19
+ end
20
+ end
21
+
22
+ def method_missing(name, *args, &block)
23
+ meth = nearest_method(name)
24
+
25
+ meth ? send(meth, *args, &block) : super
26
+ end
27
+ end
28
+
29
+ def self.included(receiver)
30
+ receiver.extend ClassMethods
31
+ receiver.send :include, InstanceMethods
32
+ end
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: close_enough
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-02 00:00:00.000000000 Z
13
+ date: 2013-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: damerau-levenshtein
@@ -70,6 +70,7 @@ executables: []
70
70
  extensions: []
71
71
  extra_rdoc_files: []
72
72
  files:
73
+ - lib/close_enough/extensions.rb
73
74
  - lib/close_enough.rb
74
75
  - spec/close_enough_spec.rb
75
76
  - spec/spec_helper.rb