Sha256: c0225d8f78d9bb43cb8a52b8af9e08363c5e97f7fe0b93bd39d2162bf5132133

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

class String
  FONETICA = [
    [/Y/, 'I'],
    [/B[RL]/, 'B'],
    [/PH/, 'F'],
    [/[MNR]G/, 'G'],
    [/G[EI]|[RMN]J/, 'J'],
    [/G[RL]/, 'G'],
    [/C[EIH]/, 'S'],
    [/CT/, 'T'],
    [/CS/, 'S'],
    [/Q|C[AOUK]?/, 'K'],
    [/LH/, 'L'],
    [/RM/, 'SM'],
    [/N/, 'M'],
    [/MD|GM|AO\b/, 'M'],
    [/NH/, 'N'],
    [/PR/, 'P'],
    [/X|TS|C|Z|RS/, 'S'],
    [/T[RL]/, 'T'],
    [/[LRS]T/, 'T'],
    [/W/, 'V'],
    [/[SZRMNL]\b/, ''],
    [/L/, 'R'],
    [/[AEIOUH]/, '']
  ]
  
  def fonetica
    word = self.gsub(/รง/i, 's') # special case
    word = I18n.transliterate(word).upcase
    
    FONETICA.each do |search, replace|
      word.gsub!(search, replace)
    end
    
    word.squeeze
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fonetica-0.1.1 lib/fonetica/string.rb
fonetica-0.1.0 lib/fonetica/string.rb