Sha256: 6ae9eb4ea2e4fee30ef86de859c30cad4cf0a662b06a15600d8b52f39f95a46d

Contents?: true

Size: 604 Bytes

Versions: 31

Compression:

Stored size: 604 Bytes

Contents

class String
  
  Ofac_SoundexChars = 'BPFVCSKGJQXZDTLMNR'
  Ofac_SoundexNums  = '111122222222334556'
  Ofac_SoundexCharsEx = '^' + Ofac_SoundexChars
  Ofac_SoundexCharsDel = '^A-Z'

  # desc: http://en.wikipedia.org/wiki/Soundex
  def ofac_soundex(census = true)
    str = upcase.delete(Ofac_SoundexCharsDel).squeeze

    str[0 .. 0] + str[1 .. -1].
      delete(Ofac_SoundexCharsEx).
      tr(Ofac_SoundexChars, Ofac_SoundexNums)[0 .. (census ? 2 : -1)].
      ljust(3, '0') rescue ''
  end

  def ofac_sounds_like(other, census = true)
    ofac_soundex(census) == other.ofac_soundex(census)
  end

end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
ofac-3.0.1 config/initializers/ruby_string_extensions.rb
kevintyll-ofac-1.0.0 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.0 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.1 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.10 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.11 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.2 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.3 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.4 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.5 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.6 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.7 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.8 lib/ofac/ruby_string_extensions.rb
kevintyll-ofac-1.1.9 lib/ofac/ruby_string_extensions.rb
ofac-3.0.0 config/initializers/ruby_string_extensions.rb
ofac-2.0.4 lib/ofac/ruby_string_extensions.rb
ofac-2.0.3 lib/ofac/ruby_string_extensions.rb
ofac-2.0.2 lib/ofac/ruby_string_extensions.rb
ofac-2.0.1 lib/ofac/ruby_string_extensions.rb
ofac-2.0.0 lib/ofac/ruby_string_extensions.rb