Sha256: 26996451926b5338edaf7c3ab46c97b0eb824bb485530b7e780cdb1685914023

Contents?: true

Size: 1.78 KB

Versions: 17

Compression:

Stored size: 1.78 KB

Contents

# encoding: utf-8

module Punchblock
  module Translator
    class Freeswitch
      module Component
        class AbstractOutput < Component
          UnrenderableDocError = Class.new OptionError

          def execute
            validate
            send_ref
            do_output
          rescue UnrenderableDocError => e
            with_error 'unrenderable document error', e.message
          rescue OptionError => e
            with_error 'option error', e.message
          end

          def execute_command(command)
            case command
            when Punchblock::Component::Stop
              command.response = true
              application 'break'
              send_complete_event Punchblock::Event::Complete::Stop.new
            else
              super
            end
          end

          private

          def do_output
            raise 'Not Implemented'
          end

          def validate
            raise OptionError, 'An SSML document is required.' unless @component_node.render_documents.first.value

            [:start_offset, :start_paused, :repeat_interval, :repeat_times, :max_time].each do |opt|
              raise OptionError, "A #{opt} value is unsupported." if @component_node.send opt
            end

            case @component_node.interrupt_on
            when :voice, :dtmf, :any
              raise OptionError, "An interrupt-on value of #{@component_node.interrupt_on} is unsupported."
            end
          end

          def concatenated_render_doc
            @component_node.render_documents.inject RubySpeech::SSML.draw do |doc, argument|
              doc + argument.value
            end
          end

          def finish_reason
            Punchblock::Component::Output::Complete::Finish.new
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.7.3 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.7.2 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.7.1 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.7.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.6.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.5.3 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.5.2 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.5.1 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.5.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.4.2 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.4.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.3.1 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.3.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.2.2 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.2.1 lib/punchblock/translator/freeswitch/component/abstract_output.rb
punchblock-2.2.0 lib/punchblock/translator/freeswitch/component/abstract_output.rb