Class: AlexaUtteranceResponder
- Inherits:
-
Object
- Object
- AlexaUtteranceResponder
- Defined in:
- lib/alexa_utteranceresponder.rb
Instance Attribute Summary collapse
-
#deviceid ⇒ Object
Returns the value of attribute deviceid.
-
#invocation ⇒ Object
readonly
Returns the value of attribute invocation.
Instance Method Summary collapse
- #ask(s, deviceid: @deviceid, &blk) ⇒ Object
-
#initialize(modelmds = [], debug: false, userid: nil, deviceid: nil) ⇒ AlexaUtteranceResponder
constructor
A new instance of AlexaUtteranceResponder.
Constructor Details
#initialize(modelmds = [], debug: false, userid: nil, deviceid: nil) ⇒ AlexaUtteranceResponder
Returns a new instance of AlexaUtteranceResponder.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/alexa_utteranceresponder.rb', line 19 def initialize(modelmds=[], debug: false, userid: nil, deviceid: nil) @debug, @userid, @deviceid = debug, userid, deviceid @models = modelmds.inject({}) do |r,x| amb = AlexaModelBuilder.new(x) r.merge(amb.invocation || amb.name => amb) end end |
Instance Attribute Details
#deviceid ⇒ Object
Returns the value of attribute deviceid.
17 18 19 |
# File 'lib/alexa_utteranceresponder.rb', line 17 def deviceid @deviceid end |
#invocation ⇒ Object (readonly)
Returns the value of attribute invocation.
16 17 18 |
# File 'lib/alexa_utteranceresponder.rb', line 16 def invocation @invocation end |
Instance Method Details
#ask(s, deviceid: @deviceid, &blk) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/alexa_utteranceresponder.rb', line 32 def ask(s, deviceid: @deviceid, &blk) puts puts ' debugger: s: ' + s.inspect if @debug invocations = @models.keys.map {|invocation| invocation.gsub(/ /,'\s') }\ .join('|') puts 'invocations: ' + invocations.inspect if @debug regex = %r{ (?<ask>(?<action>tell|ask)\s(?<invocation>#{invocations})\s(?<request>.*)){0} (?<open>(?<action>open)\s(?<invocation>#{invocations})){0} \g<ask>|\g<open> }x r2 = s.downcase.gsub(/,/,'').match(regex) puts ' debugger: r2: ' + r2.inspect if @debug puts model_id = if r2 then return respond() if r2[:action] == 'open' r2[:invocation] else puts 'searching all utterances'.info if @debug puts ('s: ' + s.inspect).debug if @debug # attempt to find the request from utterances in all skills found = @models.detect do |key, model| puts 'utterances: ' + model.utterances.map(&:downcase).inspect if @debug model.utterances.map(&:downcase).include? s end id, _ = found[0] if found end return "hmmm, I don't know that one." unless model_id puts ('model_id: ' + model_id.inspect).debug if @debug #puts '@models: ' + @models.inspect if @debug amb = @models[model_id] #puts 'amb: ' + amb.inspect if @debug aio = AskIO.new(amb.to_manifest, amb.to_model, debug: @debug, userid: @userid, deviceid: deviceid, modelid: model_id) request = r2 ? r2[:request] : s puts ('request: ' + request.inspect).debug if @debug r = aio.ask request, &blk r ? r : "I'm sorry I didn't understand what you said" end |