Class: Phonetic::Algorithm
- Inherits:
-
Object
- Object
- Phonetic::Algorithm
- Defined in:
- lib/phonetic/algorithm.rb
Overview
Base class for phonetic algorithms.
Direct Known Subclasses
Caverphone, Caverphone2, DMSoundex, DoubleMetaphone, Metaphone, NYSIIS, RefinedSoundex, Soundex
Class Method Summary collapse
-
.encode(str, options = {}) ⇒ String
Generic method for encoding string.
-
.encode_word(word, options = {}) ⇒ String
Generic method for encoding single word.
Class Method Details
.encode(str, options = {}) ⇒ String
Generic method for encoding string. Splits string by words and encodes it with encode_word.
18 19 20 21 22 |
# File 'lib/phonetic/algorithm.rb', line 18 def self.encode(str, = {}) str.scan(/\p{Word}+/).map do |word| encode_word(word, ) end.compact.reject(&:empty?).join(' ') end |
.encode_word(word, options = {}) ⇒ String
Generic method for encoding single word. Override it in your algorithm class.
8 9 10 |
# File 'lib/phonetic/algorithm.rb', line 8 def self.encode_word(word, = {}) word end |