// Calculate's Lawrence Phillip's basic metaphone (a more advanced code for matching names)
class Metaphone
TRANSFORMATIONS = [[/\A[gkp]n/ , 'n'],
[/\Ax/ , 's'],
[/\Awh/ , 'w'],
[/mb\z/ , 'm'],
[/sch/ , 'sk'],
[/x/ , 'ks'],
[/cia/ , 'xia'],
[/ch/ , 'xh'],
[/c([iey])/ , 's\1'],
[/ck/ , 'k'],
[/c/ , 'k'],
[/dg([eiy])/ , 'j\1'],
[/d/ , 't'],
[/gh/ , ''],
[/gned/ , 'ned'],
[/gn((?![aeiou])|(\z))/ , 'n'],
[/g[eiy]/ , 'j'],
[/ph/ , 'f'],
[/[aeiou]h(?![aeoiu])/ , '\1'],
[/q/ , 'k'],
[/s(h|(ia)|(io))/ , 'x\1'],
[/t((ia)|(io))/, 'x\1'],
[/th/ , '0'],
[/v/ , 'f'],
[/w(?![aeiou])/ , ''],
[/y(?![aeiou])/ , ''],
[/z/ , 's']
]
def self.create_metaphone(aWord)
word = aWord.to_s.downcase
TRANSFORMATIONS.each{|transform| word.gsub!(transform.first, transform.last)}
'a'.upto('z'){|letter| word.gsub!(letter*2, letter)}
return (word[0].chr + word[1..word.length-1].gsub(/[aeiou]/, '')).upcase
end
end