Class: Pinyin::Reader
- Inherits:
-
Object
- Object
- Pinyin::Reader
- Defined in:
- lib/pinyin.rb
Instance Method Summary collapse
-
#initialize(conv, tone) ⇒ Reader
constructor
A new instance of Reader.
- #parse(str) ⇒ Object (also: #<<)
Constructor Details
Instance Method Details
#parse(str) ⇒ Object Also known as: <<
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pinyin.rb', line 29 def parse(str) Conversions.tokenize(str).map do |s, pos| tone,syll = @tone.pop_tone(s) tsyll = Conversions.parse(@conv,syll) ini, fin = tsyll.initial, tsyll.final unless tone && fin && ini raise ParseError.new(s,pos),"Illegal syllable <#{s}> in input <#{str}> at position #{pos}." end Syllable.new(ini, fin, tone) end rescue Object => e raise ParseError.new(str,0), "Parsing of #{str.inspect} failed : #{e}" end |