Class: Fuzzzy::MethodBase

Inherits:
Object
  • Object
show all
Includes:
Redis
Defined in:
lib/fuzzzy/methods/method_base.rb

Direct Known Subclasses

Ngram::Base, Soundex::Base

Constant Summary

Constants included from Redis

Redis::INDEX_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Redis

counter_key, #counter_key, #dictionary_key, #redis, #shared_key

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/fuzzzy/methods/method_base.rb', line 5

def context
  @context
end

Instance Method Details

#index_nameObject



15
16
17
# File 'lib/fuzzzy/methods/method_base.rb', line 15

def index_name
  context[:index_name]
end

#prepare_string(string) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fuzzzy/methods/method_base.rb', line 19

def prepare_string string
  return '' unless string
  str = string.dup.downcase
  str = context[:filter].call(str) if context[:filter] && context[:filter].respond_to?(:call)
  str = (str.split - stopwords).join(' ') if context[:strip_stopwords]
  str
end

#stopwordsObject



27
28
29
30
# File 'lib/fuzzzy/methods/method_base.rb', line 27

def stopwords
  return context[:strip_stopwords] if context[:strip_stopwords] && context[:strip_stopwords].is_a?(Array) 
  Fuzzzy.stopwords
end

#with_context(cntx) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/fuzzzy/methods/method_base.rb', line 7

def with_context cntx
  @context = cntx.dup and yield if cntx
rescue => e
  raise e
ensure
  @context = nil
end