Module: Shared::IsData::Levenshtein

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/shared/is_data/levenshtein.rb

Overview

Shared code for…

Instance Method Summary (collapse)

Instance Method Details

- (Scope) nearest_by_levenshtein(compared_string = nil, column = nil, limit = 10)

Parameters:

  • (String, String, Integer)

Returns:

  • (Scope)


13
14
15
16
17
18
19
# File 'app/models/concerns/shared/is_data/levenshtein.rb', line 13

def nearest_by_levenshtein(compared_string = nil, column = nil, limit = 10)
  return self.class.none if compared_string.nil? || column.nil?
  order_str = self.class.send(:sanitize_sql_for_conditions, ["levenshtein(left(#{self.class.table_name}.#{column}, 255), ?)", compared_string[0.254] ])
  self.class.where('id <> ?', self.to_param).
    order(order_str).
    limit(limit)
end