lib/larynx/prompt.rb in larynx-0.1.2 vs lib/larynx/prompt.rb in larynx-0.1.3

- old
+ new

@@ -43,25 +43,43 @@ def termchar @options[:termchar] end + def minimum_length + @options[:min_length] || @options[:length] || 1 + end + def maximum_length @options[:max_length] || @options[:length] end + def interdigit_timeout + @options[:interdigit_timeout] + end + + def timeout + @options[:timeout] + end + def command_name ([:play, :speak, :phrase] & @options.keys).first.to_s end def message @options[command_name.to_sym] end + def valid_length? + length = input.size + length >= minimum_length && length <= (maximum_length || length) + end + def finalise call.remove_observer self - @block.call(input) + @block.arity == 2 ? @block.call(input, valid_length?) : @block.call(input) + call.clear_input end def dtmf_received(digit) if prompt_finished? call.stop_timer(:input) @@ -70,17 +88,17 @@ call.restart_timer(:digit) end end def add_digit_timer - call.timer(:digit, @options[:interdigit_timeout]) { + call.add_timer(:digit, interdigit_timeout) { call.cancel_timer :input finalise } end def add_input_timer - call.timer(:input, @options[:timeout]) { + call.add_timer(:input, timeout) { call.cancel_timer :digit finalise } end end