Class: Adhearsion::Translator::Asterisk::Component::DTMFRecognizer

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

Defined Under Namespace

Classes: BuiltinMatcherCache

Instance Method Summary collapse

Methods included from Celluloid

logger

Constructor Details

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb', line 34

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb', line 49

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



65
66
67
# File 'lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb', line 65

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