guessmethod 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/lib/guessmethod/guesser.rb +24 -8
- data/lib/guessmethod/rake.rb +1 -0
- data/lib/guessmethod/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/website/index.html +5 -4
- data/website/index.txt +4 -3
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.2.1 2008-03-29
|
2
|
+
|
3
|
+
* Medium Stuff
|
4
|
+
* Totally made GuessMethodGuesser.find_closest way better
|
5
|
+
* Made it so the specs run again
|
6
|
+
* Little Stuff
|
7
|
+
* Improved documentation for GuessMethodGuesser
|
8
|
+
* Improved "GuessMethod and Rails" section of the website
|
9
|
+
|
1
10
|
== 0.2.0 2007-12-06
|
2
11
|
|
3
12
|
* GuessRakeTask is all new. It's GuessMethod for rake!
|
data/lib/guessmethod/guesser.rb
CHANGED
@@ -2,20 +2,36 @@ require 'guessmethod/options'
|
|
2
2
|
require 'string/levenshtein'
|
3
3
|
|
4
4
|
module GuessMethod
|
5
|
-
# GuessMethodGuesser
|
6
|
-
#
|
5
|
+
# GuessMethodGuesser finds the closest matches in an array
|
6
|
+
# +haystack+ to a +needle+, based on the levenshtein distance
|
7
|
+
# of downcased string representations of the objects. However,
|
8
|
+
# it returns an empty array if there aren't matches closer
|
9
|
+
# than +GuessMethodOptions[:threshold]+
|
7
10
|
class GuessMethodGuesser
|
8
11
|
def self.find_closest(haystack, needle)
|
9
|
-
closest_distance =
|
10
|
-
|
11
|
-
|
12
|
+
closest_distance = (1.0/0.0)
|
13
|
+
closest_matches = haystack.inject([]) do |close_ones, name|
|
14
|
+
current_distance = adjusted_distance(name, needle)
|
15
|
+
if current_distance == closest_distance
|
16
|
+
close_ones << name
|
17
|
+
elsif current_distance < closest_distance
|
18
|
+
closest_distance = current_distance
|
19
|
+
[name]
|
20
|
+
else
|
21
|
+
close_ones
|
22
|
+
end
|
23
|
+
end
|
12
24
|
if closest_distance <= GuessMethodOptions[:threshold]
|
13
|
-
|
14
|
-
GuessMethodOptions[:insert_weight], GuessMethodOptions[:delete_weight],
|
15
|
-
GuessMethodOptions[:substitution_weight]) == closest_distance}
|
25
|
+
closest_matches
|
16
26
|
else
|
17
27
|
[]
|
18
28
|
end
|
19
29
|
end
|
30
|
+
|
31
|
+
def self.adjusted_distance(from, to)
|
32
|
+
from.to_s.downcase.levenshtein(to.to_s.downcase,
|
33
|
+
GuessMethodOptions[:insert_weight], GuessMethodOptions[:delete_weight],
|
34
|
+
GuessMethodOptions[:substitution_weight])
|
35
|
+
end
|
20
36
|
end
|
21
37
|
end
|
data/lib/guessmethod/rake.rb
CHANGED
data/lib/guessmethod/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/website/index.html
CHANGED
@@ -128,12 +128,13 @@ attention: invoking task db:migrate instead of db:migrat
|
|
128
128
|
<h2>GuessMethod and Rails</h2>
|
129
129
|
|
130
130
|
|
131
|
-
<p>If you’re trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing,
|
131
|
+
<p>If you’re trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing,
|
132
|
+
instead of a normal <code>require 'guessmethod'</code>, do this:</p>
|
132
133
|
|
133
134
|
|
134
|
-
<pre>require 'guessmethod'
|
135
|
+
<pre>IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }</pre>
|
135
136
|
|
136
|
-
<p>
|
137
|
+
<p>That will ensure that GuessMethod shows up after Rails does all its magic when you start a script/console session.</p>
|
137
138
|
|
138
139
|
|
139
140
|
<h2>License</h2>
|
@@ -147,7 +148,7 @@ attention: invoking task db:migrate instead of db:migrat
|
|
147
148
|
|
148
149
|
<p>Comments are welcome. Send an email to chris @@ tie-rack .. org.</p>
|
149
150
|
<p class="coda">
|
150
|
-
website generated via <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>'s <a href="http://newgem.rubyforge.org/">newgem</a>, on
|
151
|
+
website generated via <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>'s <a href="http://newgem.rubyforge.org/">newgem</a>, on 28th March 2008<br>
|
151
152
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
152
153
|
</p>
|
153
154
|
</div>
|
data/website/index.txt
CHANGED
@@ -73,11 +73,12 @@ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/
|
|
73
73
|
|
74
74
|
h2. GuessMethod and Rails
|
75
75
|
|
76
|
-
If you're trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing,
|
76
|
+
If you're trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing,
|
77
|
+
instead of a normal <code>require 'guessmethod'</code>, do this:
|
77
78
|
|
78
|
-
<pre>require 'guessmethod'
|
79
|
+
<pre>IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }</pre>
|
79
80
|
|
80
|
-
|
81
|
+
That will ensure that GuessMethod shows up after Rails does all its magic when you start a script/console session.
|
81
82
|
|
82
83
|
h2. License
|
83
84
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guessmethod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
platform:
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Shea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2008-03-29 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
requirements: []
|
83
83
|
|
84
84
|
rubyforge_project: guessmethod
|
85
|
-
rubygems_version:
|
85
|
+
rubygems_version: 1.1.0
|
86
86
|
signing_key:
|
87
87
|
specification_version: 2
|
88
88
|
summary: an aggressive spell checker for irb
|