Class: Ralyxa::Skill

Inherits:
Object
  • Object
show all
Defined in:
lib/ralyxa/skill.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Skill

Returns a new instance of Skill.



10
11
12
# File 'lib/ralyxa/skill.rb', line 10

def initialize(request)
  @request = request
end

Class Method Details

.handle(request, alexa_request_wrapper = Ralyxa::RequestEntities::Request) ⇒ Object



26
27
28
# File 'lib/ralyxa/skill.rb', line 26

def handle(request, alexa_request_wrapper = Ralyxa::RequestEntities::Request)
  new(alexa_request_wrapper.new(request)).handle
end

.handlersObject



30
31
32
# File 'lib/ralyxa/skill.rb', line 30

def handlers
  @handlers.dup
end

.intent(intent_name, handler_base_class = Ralyxa::Handler, &intent_block) ⇒ Object



20
21
22
23
24
# File 'lib/ralyxa/skill.rb', line 20

def intent(intent_name, handler_base_class = Ralyxa::Handler, &intent_block)
  intent_handler = Class.new(handler_base_class)
  intent_handler.send(:define_method, :handle, &intent_block)
  @handlers[intent_name] = intent_handler
end

Instance Method Details

#handleObject



14
15
16
17
# File 'lib/ralyxa/skill.rb', line 14

def handle
  handler = self.class.handlers[@request.intent_name]
  handler ? handler.new(@request).handle : warn(handler_not_found)
end