Module: Rake::Typo
- Defined in:
- lib/rake/typo.rb
Class Method Summary collapse
-
.candidate_tasks(task_name, tasks) ⇒ Object
Finds the Rake::Task instances in
tasks
that are most similar totask_name
and returns a list of them, ordered by name.
Class Method Details
.candidate_tasks(task_name, tasks) ⇒ Object
Finds the Rake::Task instances in tasks
that are most similar to task_name
and returns a list of them, ordered by name.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rake/typo.rb', line 9 def self.candidate_tasks(task_name, tasks) best_similarity = nil distances = tasks.map do |t| similarity = RubyFish::DamerauLevenshtein.distance(task_name, t.to_s) # start off with the first distance count we find to be the best best_similarity ||= similarity # seek the lowest we can best_similarity = similarity if similarity < best_similarity [similarity, t] end distances.select! { |sim, name| sim == best_similarity } distances.sort_by! { |sim, task| task.name } distances.map { |sim, task| task } end |