Class: Phonetic::Algorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/phonetic/algorithm.rb

Overview

Base class for phonetic algorithms.

Class Method Summary collapse

Class Method Details

.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

.encode_word(word, options = {}) ⇒ String

Generic method for encoding single word. Override it in your algorithm class.

Parameters:

  • word (String)

    the word to encode

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

    the options for the algorithm

Returns:



8
9
10
# File 'lib/phonetic/algorithm.rb', line 8

def self.encode_word(word, options = {})
  word
end