Class: Charyf::Engine::Dispatcher::BaseDispatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/charyf/engine/dispatcher/default.rb

Instance Method Summary collapse

Methods inherited from Base

#dispatch, #dispatch_async

Methods included from Strategy::BaseClass

included

Instance Method Details

#dispatch_internal(request) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/charyf/engine/dispatcher/default.rb', line 10

def dispatch_internal(request)
  # Find if session exist for this request

  context = Charyf::Engine::Context.new
  context.request = request

  # TODO process session as well
  context.session = session_processor.get.process(request)

  # Get intents
  intents = intent_processors.collect do |processor_klass|
    processor = processor_klass.instance

    processor.determine(
        request
    )
  end.flatten.sort_by do |intent|
    intent.confidence
  end.reverse

  # Sort by confidence
  best_match = intents.shift

  # Return best match with alternatives
  if best_match
    context.intent = best_match
    context.alternative_intents = intents
  end

  context.routing = routes.process(context)

  # Freeze -> #TODO deep freeze
  context.freeze

  spawn_controller(context)
end