module PinYin::Util

Constants

ASCIIMapping

Public Instance Methods

to_ascii(reading, with_tone=true) click to toggle source
# File lib/ruby_pinyin/util.rb, line 14
def to_ascii(reading, with_tone=true)
  ASCIIMapping.each do |char, (ascii, tone)|
    if reading.include? char
      if with_tone
        return reading.sub(char, ascii).concat(tone.to_s)
      else
        return reading.sub(char, ascii)
      end
    end
  end
  reading
end