Class: Ting::Conversion

Inherits:
Object
  • Object
show all
Defined in:
lib/ting/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.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ting/conversion.rb', line 29

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

  if Tone === tone
    @tone = tone
  else
    @tone = Ting::Tones.const_get(Ting.camelize(tone.to_s))
  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



27
28
29
# File 'lib/ting/conversion.rb', line 27

def name
  @name
end

#preprocessorObject (readonly)

An optional lambda that preprocesses input



20
21
22
# File 'lib/ting/conversion.rb', line 20

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



14
15
16
# File 'lib/ting/conversion.rb', line 14

def syllable_separator
  @syllable_separator
end

#tonesObject (readonly)

The tone handling object



17
18
19
# File 'lib/ting/conversion.rb', line 17

def tones
  @tones
end

Instance Method Details

#parse(string) ⇒ Object

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



43
44
# File 'lib/ting/conversion.rb', line 43

def parse(string)
end

#unparse(array) ⇒ Object

Converts an array of strings and syllable objects into a string



48
49
# File 'lib/ting/conversion.rb', line 48

def unparse(array)
end