Class: Pinyin::Conversion
- Inherits:
-
Object
- Object
- Pinyin::Conversion
- Defined in:
- lib/pinyin/conversion.rb
Overview
Base class for conversions like Hanyu pinyin, Wade-Giles, etc.
Instance Attribute Summary collapse
-
#name ⇒ Object
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.
-
#preprocessor ⇒ Object
readonly
An optional lambda that preprocesses input.
-
#syllable_separator ⇒ Object
readonly
Separator between syllables in the same word For Wade-Giles this is a dash, Hanyu pinyin uses a single quote in certain situations.
-
#tones ⇒ Object
readonly
The tone handling object.
Instance Method Summary collapse
-
#initialize(tone = :numbers, options = {}) ⇒ Conversion
constructor
A new instance of Conversion.
-
#parse(string) ⇒ Object
Converts a string into an array of strings and syllable objects.
-
#unparse(array) ⇒ Object
Converts an array of strings and syllable objects into a string.
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, = {}) @preprocessor = [: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
#name ⇒ Object (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 |
#preprocessor ⇒ Object (readonly)
An optional lambda that preprocesses input
18 19 20 |
# File 'lib/pinyin/conversion.rb', line 18 def preprocessor @preprocessor end |
#syllable_separator ⇒ Object (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 |
#tones ⇒ Object (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 |