Sha256: fb221ccc0adc5f3da01b479603e375b9038297881f290ba32f7b9d1aa3d16fc8

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8

module Adhearsion
  class CallController
    module Input
      Result = Struct.new(:status, :mode, :confidence, :utterance, :interpretation, :nlsml) do
        def to_s
          utterance
        end

        def inspect
          "#<#{self.class} status=#{status.inspect}, confidence=#{confidence.inspect}, utterance=#{utterance.inspect}, interpretation=#{interpretation.inspect}, nlsml='#{nlsml && nlsml.to_xml.split("\n").join(' ')}'>"
        end

        def utterance=(other)
          self[:utterance] = mode == :dtmf ? parse_dtmf(other) : other
        end

        def match?
          status == :match
        end

      private

        def parse_dtmf(dtmf)
          return if dtmf.nil? || dtmf.empty?
          dtmf.split(' ').inject '' do |final, digit|
            final << parse_dtmf_digit(digit)
          end
        end

        # @private
        def parse_dtmf_digit(digit)
          case tone = digit.split('-').last
          when 'star'
            '*'
          when 'pound'
            '#'
          else
            tone
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adhearsion-3.0.0.rc1 lib/adhearsion/call_controller/input/result.rb
adhearsion-3.0.0.beta2 lib/adhearsion/call_controller/input/result.rb