Class: Pinyin::Conversion

Inherits:
Object
  • Object
show all
Defined in:
lib/pinyin/conversion.rb

Overview

Base class for conversions like Hanyu pinyin, Wade-Giles, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tone = :numbers, options = {}) ⇒ Conversion

Returns a new instance of Conversion.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pinyin/conversion.rb', line 27

def initialize(tone = :numbers, options = {})
  @preprocessor = options[:preprocessor] || lambda {|s| s}

  if Tone === tone
    @tone = tone
  else
    @tone = Pinyin::Tones.const_get(tone.to_s.camelcase)
  end

  @name = self.class.name.underscore
end

Instance Attribute Details

#nameObject (readonly)

The name of this conversion, the same name used in the data file and that is also available as a method name on Initial and Final objects.

By default the underscorized class name



25
26
27
# File 'lib/pinyin/conversion.rb', line 25

def name
  @name
end

#preprocessorObject (readonly)

An optional lambda that preprocesses input



18
19
20
# File 'lib/pinyin/conversion.rb', line 18

def preprocessor
  @preprocessor
end

#syllable_separatorObject (readonly)

Separator between syllables in the same word For Wade-Giles this is a dash, Hanyu pinyin uses a single quote in certain situations



12
13
14
# File 'lib/pinyin/conversion.rb', line 12

def syllable_separator
  @syllable_separator
end

#tonesObject (readonly)

The tone handling object



15
16
17
# File 'lib/pinyin/conversion.rb', line 15

def tones
  @tones
end

Instance Method Details

#parse(string) ⇒ Object

Converts a string into an array of strings and syllable objects.



41
42
# File 'lib/pinyin/conversion.rb', line 41

def parse(string)
end

#unparse(array) ⇒ Object

Converts an array of strings and syllable objects into a string



46
47
# File 'lib/pinyin/conversion.rb', line 46

def unparse(array)
end