Sha256: 10a32e4f0dc56d6433782a96b7dc7bda1cf8defe92659572b5b6b0304172fba9

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

module Ting
  #
  # Base class for Tone classes
  #
  class Tone
    VALID_TONES  = 1..5
    MAX_TONE = NEUTRAL_TONE = 5

    class <<self
      # Add a tone to a syllable
      def add_tone(s,t)
        s
      end

      # Determine the tone of a syllable
      def peek_tone(s)
        NEUTRAL_TONE
      end

      # Remove the tone from a syllable
      def pop_tone(s)
        [NEUTRAL_TONE, s]
      end

    private
      # Make sure the tone number is in the valid range.
      # Neutral tone is always represented as NEUTRAL_TONE (5), and not 0.
      def normalize(t)
        if VALID_TONES === t
          t
        else
          t %= MAX_TONE
          t = NEUTRAL_TONE if t == 0
        end
      end

    end
  end
end

# Tone marks as a separate glyph, e.g. for Bopomofo
require "ting/tones/marks"

# Tone numbers added after the syllable
require "ting/tones/numbers"

# Tone accents, for Hanyu pinyin
require "ting/tones/accents"

# Superscript numerals, for Wade-Giles
require "ting/tones/supernum"

# IPA tone symbols
require "ting/tones/ipa"

# No tones
require "ting/tones/no_tones"

module Ting
  module Tones
    All = [Numbers, Marks, Accents, NoTones]
    VALID_TONES  = 1..5
    MAX_TONE = NEUTRAL_TONE = 5
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ting-0.3.0 lib/ting/tones.rb
ting-0.2.1 lib/ting/tones.rb
ting-0.2.0 lib/ting/tones.rb