Class: AlexaToolbox::DisplayDirective

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa_toolbox/display_directive.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, token) ⇒ DisplayDirective

Returns a new instance of DisplayDirective.



10
11
12
13
14
15
16
17
# File 'lib/alexa_toolbox/display_directive.rb', line 10

def initialize(template,token)
  @type = "Display.RenderTemplate"
  if ["BodyTemplate1","BodyTemplate2","BodyTemplate3","BodyTemplate6","ListTemplate1","ListTemplate2","ListTemplate3"].include?(template)
    @template = AlexaToolbox::DisplayDirectiveTemplate.new(template,token)
  else
    raise ArgumentError, 'Invalid display template given. Valid options are: "BodyTemplate1","BodyTemplate2","BodyTemplate3","BodyTemplate6","ListTemplate1","ListTemplate2","ListTemplate3"'
  end
end

Instance Attribute Details

#templateObject

Returns the value of attribute template.



8
9
10
# File 'lib/alexa_toolbox/display_directive.rb', line 8

def template
  @template
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/alexa_toolbox/display_directive.rb', line 8

def type
  @type
end

Instance Method Details

#build_directive(json = true) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/alexa_toolbox/display_directive.rb', line 19

def build_directive(json = true)
  data_hash = {
    "type": @type,
    "template": @template.build
  }
  json ? JSON.parse(data_hash.to_json) : data_hash
end