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 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!
@@ -2,20 +2,36 @@ require 'guessmethod/options'
2
2
  require 'string/levenshtein'
3
3
 
4
4
  module GuessMethod
5
- # GuessMethodGuesser uses map, min, and levensthtein to find the closest
6
- # match(es) in an array of strings
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 = haystack.map {|x| x.to_s.downcase.levenshtein(needle.to_s.downcase,
10
- GuessMethodOptions[:insert_weight], GuessMethodOptions[:delete_weight],
11
- GuessMethodOptions[:substitution_weight])}.min || 0
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
- haystack.find_all {|x| x.to_s.downcase.levenshtein(needle.to_s.downcase,
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
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'rake'
2
3
  require 'guessmethod/guesser'
3
4
  require 'guessmethod/outputter'
@@ -2,7 +2,7 @@ module GuessMethod
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'spec'
2
+ $LOAD_PATH << './lib'
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&#8217;re trying to have GuessMethod in your .irbrc (like me), but not have it get in the way of Rails when doing local testing, try this in your .irbrc:</p>
131
+ <p>If you&#8217;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' unless ENV.include?('RAILS_ENV')</pre>
135
+ <pre>IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }</pre>
135
136
 
136
- <p>As of 0.1.1, GuessMethod and Rails can play nice, but only if Rails shows up in the environment first. It appears that for script/console if <code>require 'guessmethod'</code> is in your irbrc, GuessMethod gets included first. But you can now safely (I think) require it after your session has started. Maybe I&#8217;ll be able to figure this issue out.</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 6th December 2007<br>
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, try this in your .irbrc:
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' unless ENV.include?('RAILS_ENV')</pre>
79
+ <pre>IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }</pre>
79
80
 
80
- As of 0.1.1, GuessMethod and Rails can play nice, but only if Rails shows up in the environment first. It appears that for script/console if <code>require 'guessmethod'</code> is in your irbrc, GuessMethod gets included first. But you can now safely (I think) require it after your session has started. Maybe I'll be able to figure this issue out.
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.0
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: 2007-12-06 00:00:00 -07:00
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: 0.9.5
85
+ rubygems_version: 1.1.0
86
86
  signing_key:
87
87
  specification_version: 2
88
88
  summary: an aggressive spell checker for irb