Module: Fuzzy

Defined in:
lib/fuzzy.rb,
lib/fuzzy/version.rb

Constant Summary collapse

VERSION =
"9000.0.2"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



5
6
7
8
9
# File 'lib/fuzzy.rb', line 5

def method_missing sym, *args, &block
  chosen_method = fuzzy_match sym
  puts "You requested #{sym}, our survey says: #{chosen_method}"
  self.send chosen_method, *args, &block
end

Instance Method Details

#fuzzy_match(requested_method) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fuzzy.rb', line 12

def fuzzy_match requested_method
  max = - (1.0/0)
  matcher = FuzzyStringMatch::JaroWinkler.new.create :pure

  chosen_method = nil
  methods.each do |m|
    distance = matcher.getDistance m.to_s, requested_method.to_s
    if distance > max
      max = distance
      chosen_method = m.to_sym unless m.to_sym == :method_missing
    end

  end
  chosen_method
end