Method: Text::Soundex.soundex_str
- Defined in:
- lib/flatulent/text/soundex.rb
.soundex_str(str) ⇒ Object
returns nil if the value couldn’t be calculated (empty-string, wrong-character) do not change the parameter “str”
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/flatulent/text/soundex.rb', line 29 def soundex_str(str) return nil if str.empty? str = str.upcase last_code = get_code(str[0,1]) soundex_code = str[0,1] for index in 1...(str.size) do return soundex_code if soundex_code.size == 4 code = get_code(str[index,1]) if code == "0" then last_code = nil elsif code == nil then return nil elsif code != last_code then soundex_code += code last_code = code end end # for return soundex_code + "000"[0,4-soundex_code.size] end |