Module: RubyFish::DoubleMetaphone
- Extended by:
- DoubleMetaphone
- Included in:
- DoubleMetaphone
- Defined in:
- lib/rubyfish/double_metaphone.rb
Overview
stolen from english.rubyforge.org/
Instance Method Summary collapse
Instance Method Details
#phonetic_code(string) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubyfish/double_metaphone.rb', line 6 def phonetic_code string str = string.to_s primary, secondary, current = '', '', 0 original, length, last = "#{str} ".upcase, str.length, str.length - 1 if /^GN|KN|PN|WR|PS$/ =~ original[0, 2] current += 1 end if 'X' == original[0, 1] primary << 'S' secondary << 'S' current += 1 end while primary.length < 4 || secondary.length < 4 break if current > str.length a, b, c = lookup(original, current, length, last) primary << a if a secondary << b if b current += c if c end primary, secondary = primary[0, 4], secondary[0, 4] [primary, (primary == secondary ? nil : secondary)] end |