Class: Ting::Reader

Inherits:
Object
  • Object
show all
Includes:
Procable
Defined in:
lib/ting/reader.rb

Instance Method Summary collapse

Methods included from Procable

#memoize, #to_proc

Constructor Details

#initialize(conv, tone) ⇒ Reader

Returns a new instance of Reader.



5
6
7
8
# File 'lib/ting/reader.rb', line 5

def initialize(conv, tone)
  @conv = conv.to_s
  @tone = Tones.const_get Ting.camelize(tone.to_s)
end

Instance Method Details

#parse(str) ⇒ Object Also known as: <<, call



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ting/reader.rb', line 10

def parse(str)
  Conversions.tokenize(str).map do |token, pos|
    tone, syll = @tone.pop_tone(token)
    tsyll = Conversions.parse(@conv, syll)
    ini, fin = tsyll.initial, tsyll.final
    unless tone && fin && ini
      raise ParseError.new(token, pos),"Illegal syllable <#{token}> in input <#{str}> at position #{pos}."
    end
    tsyll + tone
  end
rescue Object => e
  raise ParseError.new(str, 0, e), "Parsing of #{str.inspect} failed : #{e}"
end