class FuzzyWords

Attributes

max_fuzz[RW]

Public Class Methods

new(max_fuzz=4) click to toggle source
# File lib/fuzzy_matcher/fuzzy_words.rb, line 5
def initialize(max_fuzz=4)
  @max_fuzz = max_fuzz
end

Public Instance Methods

find_word(text, word) click to toggle source
# File lib/fuzzy_matcher/fuzzy_words.rb, line 16
def find_word(text, word)
  matches = []
  fuzz = 1
  while fuzz <= @max_fuzz do
    matches = text.extend(TRE).ascan word, TRE.fuzziness(fuzz)
    break if !matches.empty?
    fuzz = fuzz + 1
  end
  matches
end
find_words(file, words) click to toggle source
# File lib/fuzzy_matcher/fuzzy_words.rb, line 9
def find_words(file, words)
  words.map do |w|
    matches = find_word file, w
    { word: w, matches: matches } if !matches.empty?
  end.compact
end