Module: Fuzzzy

Extended by:
ActiveSupport::Autoload, Fuzzzy
Included in:
Fuzzzy
Defined in:
lib/fuzzzy.rb,
lib/fuzzzy/index.rb,
lib/fuzzzy/redis.rb,
lib/fuzzzy/version.rb,
lib/fuzzzy/server/http.rb,
lib/fuzzzy/methods/indexer.rb,
lib/fuzzzy/orm/mongoid/index.rb,
lib/fuzzzy/methods/ngram/base.rb,
lib/fuzzzy/methods/method_base.rb,
lib/fuzzzy/methods/soundex/base.rb,
lib/fuzzzy/methods/ngram/indexer.rb,
lib/fuzzzy/methods/ngram/searcher.rb,
lib/fuzzzy/methods/soundex/indexer.rb,
lib/fuzzzy/methods/soundex/searcher.rb

Defined Under Namespace

Modules: Index, Indexer, Mongoid, Ngram, Redis, Server, Soundex Classes: MethodBase

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#configure {|_self| ... } ⇒ Object

Fuzzzy.configure do |config|

config.logger = Logger.new($stdout)
config.redis = ::Redis.new(
  :host => 'localhost',
  :port => 6379,
  :database => 0
)
config.stopwords = %w{the stopwords list}

end

Yields:

  • (_self)

Yield Parameters:

  • _self (Fuzzzy)

    the object that the method was called on



62
63
64
# File 'lib/fuzzzy.rb', line 62

def configure
  yield self
end

#default_stopwordsObject



111
112
113
# File 'lib/fuzzzy.rb', line 111

def default_stopwords
  @default_stopwords ||= load_stopwords(Fuzzzy.root.join('dictionary', 'en_stopwords.yml').to_s)
end

#envObject



115
116
117
118
119
# File 'lib/fuzzzy.rb', line 115

def env
  return Rails.env if defined?(Rails)
  return Sinatra::Base.environment.to_s if defined?(Sinatra)
  ENV["RACK_ENV"] || 'development'
end

#load_stopwords(options) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fuzzzy.rb', line 98

def load_stopwords options
  if options.is_a?(Hash)
    stops = load_stopwords(options[:stopwords])
    options[:default] ? (stops + default_stopwords) : stops
  elsif options.is_a?(Array)
    options
  elsif options.is_a?(String) || options.is_a?(Pathname)
    YAML.load_file(options)
  else
    []
  end
end

#loggerObject



66
67
68
69
# File 'lib/fuzzzy.rb', line 66

def logger
  @logger = default_logger unless defined?(@logger)
  @logger
end

#logger=(logger) ⇒ Object



71
72
73
74
75
76
# File 'lib/fuzzzy.rb', line 71

def logger=(logger)
  case logger
    when Logger then @logger = logger
    when false, nil then @logger = nil
  end
end

#redisObject



78
79
80
81
82
83
84
# File 'lib/fuzzzy.rb', line 78

def redis
  @redis ||= ::Redis.new(
    :host => 'localhost',
    :port => 6379,
    :database => 0
  )
end

#redis=(connection) ⇒ Object



86
87
88
# File 'lib/fuzzzy.rb', line 86

def redis= connection
  @redis = connection
end

#rootObject



121
122
123
# File 'lib/fuzzzy.rb', line 121

def root
  @root ||= Pathname.new(File.expand_path('.'))
end

#stopwordsObject



90
91
92
# File 'lib/fuzzzy.rb', line 90

def stopwords
  @stopwords ||= default_stopwords
end

#stopwords=(value) ⇒ Object



94
95
96
# File 'lib/fuzzzy.rb', line 94

def stopwords= value
  @stopwords = load_stopwords(value).uniq
end