class Phonetic::RefinedSoundex

Class for encoding string to Refined Soundex code. A refined soundex code is optimized for spell checking words.

@example

Phonetic::RefinedSoundex.encode('Caren')   # => 'C30908'
Phonetic::RefinedSoundex.encode('Hayers')  # => 'H093'
Phonetic::RefinedSoundex.encode('Lambard') # => 'L7081096'

Constants

CODE

Public Class Methods

encode_word(word, options = {}) click to toggle source

Encode word to its Refined Soundex value

# File lib/phonetic/refined_soundex.rb, line 25
def self.encode_word(word, options = {})
  w = word.upcase
  res = w[0]
  pg = nil
  w.chars.each do |c|
    g = CODE[c.to_sym] || 0
    if pg != g
      res += g.to_s
      pg = g
    end
  end
  res
end