class Phonetic::RefinedNYSIIS
This class implements Refined NYSIIS
algorithm. @see www.dropby.com/NYSIIS.html NYSIIS
Code @example
Phonetic::RefinedNYSIIS.encode('Aumont') # => 'ANAD' Phonetic::RefinedNYSIIS.encode('Schmidt') # => 'SNAD' Phonetic::RefinedNYSIIS.encode('Phoenix') # => 'FANAC'
Constants
- FIRST_MAP
- SECOND_MAP
Public Class Methods
encode(str, options = { trim: true })
click to toggle source
Convert string to Refined NYSIIS
code
# File lib/phonetic/refined_nysiis.rb, line 46 def self.encode(str, options = { trim: true }) self.encode_word(str, options) end
encode_word(word, options = { trim: true })
click to toggle source
Convert word to its Refined NYSIIS
code
# File lib/phonetic/refined_nysiis.rb, line 51 def self.encode_word(word, options = { trim: true }) return '' if !word or word.empty? trim = options[:trim] w = word.upcase.strip w.gsub! /\s([IV]+|[JS]R)$/, '' w.gsub! /[^A-Z]/, '' return if w.empty? FIRST_MAP.each{ |rx, v| w.gsub!(rx, v) } first_char = w[0] SECOND_MAP.each{ |rx, v| w.gsub!(rx, v) } w.gsub! /^A*/, first_char if vowel?(first_char) w = w[0..5] if trim w end
Private Class Methods
vowel?(char)
click to toggle source
# File lib/phonetic/refined_nysiis.rb, line 68 def self.vowel?(char) char =~ /^[AEIOU]/ end