Sha256: 3daf39f1f7caeddc50242347afacff61d1950d0f16c14131dab99006c9b9c402

Contents?: true

Size: 960 Bytes

Versions: 1

Compression:

Stored size: 960 Bytes

Contents

require 'phonet_api'
require 'iconv'

module Phonet

  # constants for function "phonet" (do not change)
  PHONET_FIRST_RULES = 0
  PHONET_SECOND_RULES =  1024

  # If you don't want rules for one or more of the       ****/
  # following languages, delete the corresponding macro  ****/
  PHONET_NO_LANGUAGE = 1
  PHONET_GERMAN  =     2

  PHONET_DEFAULT_LANGUAGE  = PHONET_GERMAN
  
  def Phonet.phonet(string, rules)
    input = Phonet.utf8_to_iso88591(string)
    buffer = "\000" * (input.length * 2)
    Phonet_api.phonet(input, buffer, buffer.length, rules)
    result =  buffer.unpack("Z*").join
    result = Phonet.iso88591_to_utf8(result)
    return result
  end

  def Phonet.set_language(language)
    Phonet_api.set_phonet_language(language)
  end

  def Phonet.utf8_to_iso88591(string)
    return Iconv.conv("ISO-8859-1", "UTF-8", string)
  end

  def Phonet.iso88591_to_utf8(string)
    return Iconv.conv("UTF-8", "ISO-8859-1", string)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phonet-0.0.1 lib/phonet.rb