feeling_lucky 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c3170d4b81f5d73ed496468e3b51a78bcafe41b
4
+ data.tar.gz: 3dbf5ba8941be586c89efb856020b361c48da8a2
5
+ SHA512:
6
+ metadata.gz: ad7b919920ccba303e6a4904562fdf430ddc2bb66fd071274c43753d9d74722b8ca0051bf45a30b5c9fed6fb69b3d5c5d4ad7cda2f773605491077860da9b24c
7
+ data.tar.gz: c2dd7ba31dd5263ae25bd503a05147ed795fb4ee266a2df15b0739042f3a4f599e0d47108f4919e1711b8f15be14d170a28d2289290fdf7d38f30fe79ab7c2b0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in feeling_lucky.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Shervin Aflatooni
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,40 @@
1
+ # Feeling Lucky
2
+
3
+ Hate NoMethodErrors? Are you feeling lucky?
4
+
5
+ This gem will make spelling methods correctly a thing of the past. We are truly in the future now!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'feeling_lucky'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install feeling_lucky
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ Object.metheds
27
+
28
+ # => [:allocate, :new, :superclass, :freeze, :===, :==, :<=>, :<, :<=, :>, :>=, :to_s, :inspect, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?, :const_missing, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set, :class_variable_defined?, :public_constant, :private_constant, :singleton_class?, :include, :prepend, :module_exec, :class_exec, :module_eval, :class_eval, :method_defined?, :public_method_defined?, :private_method_defined?, :protected_method_defined?, :public_class_method, :private_class_method, :autoload, :autoload?, :instance_method, :public_instance_method, :nil?, :=~, :!~, :eql?, :hash, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
29
+
30
+ "hello".uppcase
31
+ # => "HELLO"
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/[my-github-username]/feeling_lucky/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new('spec') do |t|
5
+ t.verbose = true
6
+ end
7
+
8
+
9
+ task :default => [:spec]
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'feeling_lucky/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "feeling_lucky"
8
+ spec.version = FeelingLucky::VERSION
9
+ spec.authors = ["Shervin Aflatooni"]
10
+ spec.email = ["shervinaflatooni@gmail.com"]
11
+ spec.summary = %q{Hate NoMethodErrors? Are you feeling lucky?.}
12
+ spec.description = %q{Do you hate spelling mistakes? Did you forget what you called that method or attribute? Feeling lucky will fix that for you!}
13
+ spec.homepage = "https://github.com/Shervanator/feeling_lucky"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,3 @@
1
+ module FeelingLucky
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,74 @@
1
+ require 'feeling_lucky/version'
2
+
3
+ module Levenshtein
4
+ # This code is based directly on the Text gem implementation
5
+ # Returns a value representing the "cost" of transforming str1 into str2
6
+ # taken from https://github.com/threedaymonk/text/blob/master/lib/text/levenshtein.rb
7
+ def distance(str1, str2)
8
+ n = str1.length
9
+ m = str2.length
10
+ return m if n.zero?
11
+ return n if m.zero?
12
+
13
+ d = (0..m).to_a
14
+ x = nil
15
+
16
+ str1.each_char.with_index(1) do |char1, i|
17
+ str2.each_char.with_index do |char2, j|
18
+ cost = (char1 == char2) ? 0 : 1
19
+ x = min3(
20
+ d[j+1] + 1, # insertion
21
+ i + 1, # deletion
22
+ d[j] + cost # substitution
23
+ )
24
+ d[j] = i
25
+ i = x
26
+ end
27
+ d[m] = x
28
+ end
29
+
30
+ x
31
+ end
32
+ module_function :distance
33
+
34
+ private
35
+
36
+ def min3(a, b, c) # :nodoc:
37
+ if a < b && a < c
38
+ a
39
+ elsif b < c
40
+ b
41
+ else
42
+ c
43
+ end
44
+ end
45
+ module_function :min3
46
+ end
47
+
48
+ def threshold(word)
49
+ (word.size * 0.3).ceil
50
+ end
51
+
52
+ class Object
53
+ def method_missing(meth, *args, &block)
54
+ all_methods = self.methods + self.singleton_methods
55
+ meth_str = meth.to_s
56
+ threshold = threshold(meth_str)
57
+ good_methods = all_methods.select {|word| Levenshtein.distance(meth_str, word.to_s) <= threshold }
58
+ if good_methods.length > 0
59
+ puts "#{self.class}:: for #{meth} picked #{good_methods.first}"
60
+ begin
61
+ self.send(good_methods.first, *args, &block)
62
+ rescue Exception => e
63
+ super
64
+ end
65
+ else
66
+ super
67
+ end
68
+ end
69
+ end
70
+
71
+ module FeelingLucky
72
+ end
73
+
74
+
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Feeling Lucky' do
4
+ it 'doesnt effect working methods' do
5
+ expect("hello".upcase).to eq("HELLO")
6
+ end
7
+
8
+ it 'corrects spelling mistakes' do
9
+ expect("hello".uppcase).to eq("HELLO")
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'feeling_lucky'
2
+
3
+ RSpec.configure do |config|
4
+ config.order = 'random'
5
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feeling_lucky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shervin Aflatooni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Do you hate spelling mistakes? Did you forget what you called that method
56
+ or attribute? Feeling lucky will fix that for you!
57
+ email:
58
+ - shervinaflatooni@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - feeling_lucky.gemspec
70
+ - lib/feeling_lucky.rb
71
+ - lib/feeling_lucky/version.rb
72
+ - spec/feeling_lucky/feeling_lucky_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: https://github.com/Shervanator/feeling_lucky
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Hate NoMethodErrors? Are you feeling lucky?.
98
+ test_files:
99
+ - spec/feeling_lucky/feeling_lucky_spec.rb
100
+ - spec/spec_helper.rb