Sha256: a558a233bd5ff3cf801eb2386cb5365244ac701a59bdd74bdec3441732a607fc

Contents?: true

Size: 942 Bytes

Versions: 10

Compression:

Stored size: 942 Bytes

Contents

module AdhearsionASR
  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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
adhearsion-asr-1.5.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.4.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.3.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.2.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.1.1 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.1.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.0.1 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.0.0 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-1.0.0.beta1 lib/adhearsion-asr/ask_grammar_builder.rb
adhearsion-asr-0.1.0 lib/adhearsion-asr/ask_grammar_builder.rb