Sha256: 8912d42fd4431cec773130fe9105c2b5debbdd5a95f86c913a250c6295d1e7af

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

# -*- coding: utf-8 -*-

# Handle several romanization systems for Mandarin Chinese
#
# Author::     Arne Brasseur (arne@arnebrasseur.net)
# Copyright::  Copyright (c) 2007-2014, Arne Brasseur
# Licence::    GNU General Public License, v3

require 'ting/version'
require 'ting/groundwork'
require 'ting/exception'

require 'ting/tones'
require 'ting/conversion'
require 'ting/conversions'
require 'ting/conversions/hanyu'

require 'ting/procable'
require 'ting/reader'
require 'ting/writer'
require 'ting/converter'
require 'ting/hanyu_pinyin_parser'
require 'ting/memoize_call'

module Ting
  class << self

    def reader(format, tones)
      Reader.new(format,tones)
    end

    def writer(format, tones)
      Writer.new(format,tones)
    end

    def from(from, from_tone)
      Converter.new(from, from_tone, nil, nil)
    end

    def camelize(str)
      str = str.dup
      str.gsub!(/(?:_+|-+)([a-z])/){ $1.upcase }
      str.gsub!(/(\A|\s)([a-z])/){ $1 + $2.upcase }
      str
    end

    SYLLABLE_CACHE = Hash.new do |hsh, syll|
      hsh[syll] = Ting.writer(:hanyu, :accents).(
        Ting.reader(:hanyu, :numbers).(syll.downcase)
      )
    end


    def pretty_tones(string)
      string.gsub('u:','ü').gsub(/[A-Za-züÜ]{1,7}\d?/) do |syll|
        SYLLABLE_CACHE[syll]
      end
    end

    def bpmf(string)
      string.gsub('u:','ü').scan(/[A-Za-züÜ]{1,7}\d?/).map do |m|
        Ting.writer(:zhuyin, :marks).(
          Ting.reader(:hanyu, :numbers).(m.downcase)
        )
      end.join(' ')
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ting-0.11.0 lib/ting.rb