Class: ActsAsIndexed::TokenNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_indexed/token_normalizer.rb

Class Method Summary collapse

Class Method Details

.process(arr, options = {}) ⇒ Object

Takes an array of tokens.

  • Downcases the tokens when :normalize_case option is passed.

  • Removes tokens of :min_token_length when option is passed.

Returns the resulting array of tokens.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_indexed/token_normalizer.rb', line 8

def self.process(arr, options={})
  if options[:normalize_case]
    arr = arr.map{ |t| t.downcase }
  end

  if options[:min_token_length]
    arr = arr.reject{ |w| w.size < options[:min_token_length] }
  end

  arr
end