Class: AlexaSkill::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa-skill/registry.rb

Class Method Summary collapse

Class Method Details

.listObject



10
11
12
# File 'lib/alexa-skill/registry.rb', line 10

def self.list
  INTENTS
end

.register(name, intent) ⇒ Object



6
7
8
# File 'lib/alexa-skill/registry.rb', line 6

def self.register(name, intent)
  INTENTS[name] = intent
end

.schemaObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/alexa-skill/registry.rb', line 24

def self.schema
  response = {intents:[]}
  INTENTS.each do |name, intent|
    intent_schema = {intent: name, slots: []}
    intent.slots.each do |slot, properties|
      if properties.is_a?(String)
        slot_type = properties
      elsif properties.is_a?(Array)
        slot_type = "LIST_OF_#{slot.upcase}"
      else
        raise ArgumentError, "Property '#{properties}` not recognized"
      end

      intent_schema[:slots] << {
        name: slot,
        type: slot_type
      }
    end
    response[:intents] << intent_schema
  end
  response
end

.typesObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/alexa-skill/registry.rb', line 47

def self.types
  response = {}
  INTENTS.each do |name, intent|
    intent.slots.each do |slot, properties|
      if properties.is_a?(Array)
        slot_type = "LIST_OF_#{slot.upcase}"
        response[slot_type] = properties
      end
    end
  end
  response
end

.utterancesObject



14
15
16
17
18
19
20
21
22
# File 'lib/alexa-skill/registry.rb', line 14

def self.utterances
  response = []
  INTENTS.each do |name, intent|
    intent.utterances.each do |utter|
      response << "#{name} #{utter}"
    end
  end
  response
end