Class: Punchblock::Translator::DTMFRecognizer

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/punchblock/translator/dtmf_recognizer.rb

Defined Under Namespace

Classes: BuiltinMatcherCache

Instance Method Summary collapse

Constructor Details

#initialize(responder, grammar, initial_timeout = nil, inter_digit_timeout = nil, terminator = nil) ⇒ DTMFRecognizer


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/punchblock/translator/dtmf_recognizer.rb', line 28

def initialize(responder, grammar, initial_timeout = nil, inter_digit_timeout = nil, terminator = nil)
  @responder = responder
  self.initial_timeout = initial_timeout || -1
  self.inter_digit_timeout = inter_digit_timeout || -1
  @terminator = terminator
  @finished = false

  @matcher = if grammar.url
    BuiltinMatcherCache.instance.get(grammar.url)
  else
    RubySpeech::GRXML::Matcher.new RubySpeech::GRXML.import(grammar.value.to_s)
  end
  @buffer = ""
end

Instance Method Details

#<<(digit) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/punchblock/translator/dtmf_recognizer.rb', line 43

def <<(digit)
  cancel_initial_timer
  @buffer << digit unless terminating?(digit)
  case (match = get_match)
  when RubySpeech::GRXML::NoMatch
    finalize :nomatch
  when RubySpeech::GRXML::MaxMatch
    finalize :match, match
  when RubySpeech::GRXML::Match
    finalize :match, match if terminating?(digit)
  when RubySpeech::GRXML::PotentialMatch
    finalize :nomatch if terminating?(digit)
  end
  reset_inter_digit_timer unless @finished
end

#start_timersObject


59
60
61
# File 'lib/punchblock/translator/dtmf_recognizer.rb', line 59

def start_timers
  begin_initial_timer @initial_timeout/1000 unless @initial_timeout == -1
end