Method: Phonetic::Algorithm.encode

Defined in:
lib/phonetic/algorithm.rb

.encode(str, options = {}) ⇒ String

Generic method for encoding string. Splits string by words and encodes it with encode_word.

Parameters:

  • str (String)

    the string to encode.

  • options (Hash) (defaults to: {})

    the options for algorithm.

Returns:

  • (String)

    the space separated codes of words from input string.



18
19
20
21
22
# File 'lib/phonetic/algorithm.rb', line 18

def self.encode(str, options = {})
  str.scan(/\p{Word}+/).map do |word|
    encode_word(word, options)
  end.compact.reject(&:empty?).join(' ')
end