metherd-missing 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/metherd-missing.rb +15 -0
- data/lib/metherd-missing/levenshtein_distance.rb +56 -0
- data/lib/metherd-missing/trie_node.rb +20 -0
- data/lib/metherd-missing/version.rb +3 -0
- data/metherd-missing.gemspec +19 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrew Vos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Metherd::Missing
|
2
|
+
|
3
|
+
Getting tired of having to go in and modify code each time you make a type?
|
4
|
+
metherd-missing to the rescue!
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'metherd-missing'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install metherd-missing
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require "metherd-missing"
|
24
|
+
|
25
|
+
[3, 2, 1].revrse #=> [1, 2, 3]
|
26
|
+
|
27
|
+
"LOL".dwncase #=> "lol"
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "metherd-missing/version"
|
2
|
+
require "metherd-missing/levenshtein_distance"
|
3
|
+
require "metherd-missing/trie_node"
|
4
|
+
|
5
|
+
module Kernel
|
6
|
+
def method_missing method
|
7
|
+
possible_method_names = self.methods.map(&:to_s)
|
8
|
+
results = MetherdMissing::LevenshteinDistance.new(possible_method_names).search(method, 1)
|
9
|
+
if results.any?
|
10
|
+
self.send(results.keys.first.to_s)
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module MetherdMissing
|
2
|
+
class LevenshteinDistance
|
3
|
+
def initialize(words)
|
4
|
+
@trie = TrieNode.new
|
5
|
+
words.each do |word|
|
6
|
+
@trie.insert(word)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def search word, maximum_distance
|
11
|
+
current_row = (0..word.length).to_a
|
12
|
+
results = {}
|
13
|
+
@trie.children.keys.each do |letter|
|
14
|
+
search_recursive(
|
15
|
+
@trie.children[letter],
|
16
|
+
letter,
|
17
|
+
word,
|
18
|
+
current_row,
|
19
|
+
results,
|
20
|
+
maximum_distance
|
21
|
+
)
|
22
|
+
end
|
23
|
+
results
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def search_recursive node, letter, word, previous_row, results, maximum_distance
|
29
|
+
columns = word.length + 1
|
30
|
+
current_row = [previous_row.first + 1]
|
31
|
+
|
32
|
+
(1...columns).each do |column|
|
33
|
+
insert_cost = current_row[column - 1] + 1
|
34
|
+
delete_cost = previous_row[column] + 1
|
35
|
+
|
36
|
+
if word[column - 1] != letter[0]
|
37
|
+
replace_cost = previous_row[column - 1] + 1
|
38
|
+
else
|
39
|
+
replace_cost = previous_row[column - 1]
|
40
|
+
end
|
41
|
+
|
42
|
+
current_row << [insert_cost, delete_cost, replace_cost].min
|
43
|
+
end
|
44
|
+
|
45
|
+
if current_row.last <= maximum_distance && node.word
|
46
|
+
results[node.word] = current_row.last
|
47
|
+
end
|
48
|
+
|
49
|
+
if current_row.min <= maximum_distance
|
50
|
+
node.children.keys.each do |letter|
|
51
|
+
search_recursive(node.children[letter], letter, word, current_row, results, maximum_distance)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MetherdMissing
|
2
|
+
class TrieNode
|
3
|
+
attr_accessor :word, :children
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@children = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def insert word
|
10
|
+
node = self
|
11
|
+
word.each_char do |letter|
|
12
|
+
unless node.children[letter]
|
13
|
+
node.children[letter] = TrieNode.new
|
14
|
+
end
|
15
|
+
node = node.children[letter]
|
16
|
+
end
|
17
|
+
node.word = word
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metherd-missing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "metherd-missing"
|
8
|
+
gem.version = MetherdMissing::VERSION
|
9
|
+
gem.authors = ["Andrew Vos"]
|
10
|
+
gem.email = ["andrew.vos@gmail.com"]
|
11
|
+
gem.description = %q{Translates misspellings of method calls to actual method calls!}
|
12
|
+
gem.summary = %q{Translates misspellings of method calls to actual method calls!}
|
13
|
+
gem.homepage = "http://github.com/AndrewVos/metherd-missing"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metherd-missing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Vos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Translates misspellings of method calls to actual method calls!
|
15
|
+
email:
|
16
|
+
- andrew.vos@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/metherd-missing.rb
|
27
|
+
- lib/metherd-missing/levenshtein_distance.rb
|
28
|
+
- lib/metherd-missing/trie_node.rb
|
29
|
+
- lib/metherd-missing/version.rb
|
30
|
+
- metherd-missing.gemspec
|
31
|
+
homepage: http://github.com/AndrewVos/metherd-missing
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Translates misspellings of method calls to actual method calls!
|
55
|
+
test_files: []
|