Module: PinYin::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/ruby-pinyin/util.rb

Constant Summary collapse

ASCIIMapping =
{
  'ā' => ['a', 1], 'ē' => ['e', 1], 'ī' => ['i', 1], 'ō' => ['o', 1], 'ū' => ['u', 1], 'ǖ' => ['v', 1],
  'á' => ['a', 2], 'é' => ['e', 2], 'í' => ['i', 2], 'ó' => ['o', 2], 'ú' => ['u', 2], 'ǘ' => ['v', 2],
  'ǎ' => ['a', 3], 'ě' => ['e', 3], 'ǐ' => ['i', 3], 'ǒ' => ['o', 3], 'ǔ' => ['u', 3], 'ǚ' => ['v', 3],
  'à' => ['a', 4], 'è' => ['e', 4], 'ì' => ['i', 4], 'ò' => ['o', 4], 'ù' => ['u', 4], 'ǜ' => ['v', 4]
}

Instance Method Summary collapse

Instance Method Details

#to_ascii(reading, with_tone = true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby-pinyin/util.rb', line 12

def to_ascii(reading, with_tone=true)
  reading = reading.dup

  ASCIIMapping.each do |char, (ascii, tone)|
    if reading.tr!(char, ascii) && with_tone
      return reading.concat(tone.to_s)
    end
  end

  reading
end