Sha256: e378fe53cf83c02b8fccb983bf123c8a38d8a069e2d7cc5468876fd06e5a1d3a

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8

module Adhearsion
  class CallController
    module Input
      class AskGrammarBuilder
        def initialize(options)
          @options = options
        end

        def grammars
          @grammars ||= build_grammars
        end

      private

        def build_grammars
          grammars = []

          grammars.concat [@options[:grammar]].flatten.compact.map { |val| {value: val} } if @options[:grammar]
          grammars.concat [@options[:grammar_url]].flatten.compact.map { |val| {url: val} } if @options[:grammar_url]

          if grammars.empty?
            limit = @options[:limit]
            grammar = RubySpeech::GRXML.draw mode: :dtmf, root: 'digits' do
              rule id: 'digits', scope: 'public' do
                item repeat: "0-#{limit}" do
                  one_of do
                    0.upto(9) { |d| item { d.to_s } }
                    item { "#" }
                    item { "*" }
                  end
                end
              end
            end
            grammars << {value: grammar}
          end

          grammars
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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