class Phonetic::Algorithm

Base class for phonetic algorithms.

Public Class Methods

encode(str, options = {}) click to toggle source

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

@param [String] str the string to encode. @param [Hash] options the options for algorithm. @return [String] the space separated codes of words from input string.

# 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
encode_word(word, options = {}) click to toggle source

Generic method for encoding single word. Override it in your algorithm class. @param [String] word the word to encode @param [Hash] options the options for the algorithm @return [String] the word

# File lib/phonetic/algorithm.rb, line 8
def self.encode_word(word, options = {})
  word
end