Class: AlexaToolbox::DisplayDirectiveTemplate

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

Overview

Handles creating display directives in responses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, token, title = nil, back_button = "VISIBLE") ⇒ DisplayDirectiveTemplate



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

def initialize(type,token,title = nil,back_button = "VISIBLE")
  @type = type
  @token = token
  @back_button = back_button
  @background_image = AlexaToolbox::DisplayDirectiveImage.new
  @title = title
  @text_content = AlexaToolbox::DisplayDirectiveTextContent.new
  @list_items = []
  @image = nil
end

Instance Attribute Details

#back_buttonObject

Returns the value of attribute back_button.



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

def back_button
  @back_button
end

#background_imageObject

Returns the value of attribute background_image.



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

def background_image
  @background_image
end

#list_itemsObject

Returns the value of attribute list_items.



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

def list_items
  @list_items
end

#text_contentObject

Returns the value of attribute text_content.



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

def text_content
  @text_content
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#add_image_object(image) ⇒ Object



37
38
39
# File 'lib/alexa_toolbox/display_directive_template.rb', line 37

def add_image_object(image)
  @image = image
end

#add_item_to_list(token, image, text_content) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/alexa_toolbox/display_directive_template.rb', line 41

def add_item_to_list(token,image,text_content)
  list_item = {}
  list_item[:token] = token if !token.nil?
  list_item[:image] = image.build if !image.nil?
  list_item[:textContent] = text_content.build if !text_content.nil?
  @list_items.push(list_item)
end

#add_title(title) ⇒ Object



33
34
35
# File 'lib/alexa_toolbox/display_directive_template.rb', line 33

def add_title(title)
  @title = title
end

#buildObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/alexa_toolbox/display_directive_template.rb', line 49

def build
  template = {
    :type => @type,
    :token => @token,
    :backButton => @back_button
  }
  template[:backgroundImage] = @background_image.build if @background_image.valid?
  template[:title] = @title if !@title.nil? && @title.length > 0
  template[:textContent] = @text_content.build if @text_content.valid?
  template[:image] = @image.build if !@image.nil? && ["ListTemplate1","ListTemplate2","ListTemplate3","BodyTemplate2","BodyTemplate3","BodyTemplate6"].include?(@type)
  template[:listItems] = @list_items if !@list_items.empty?

  template
end

#hide_back_buttonObject



25
26
27
# File 'lib/alexa_toolbox/display_directive_template.rb', line 25

def hide_back_button
  @back_button = "HIDDEN"
end

#set_token(token) ⇒ Object



21
22
23
# File 'lib/alexa_toolbox/display_directive_template.rb', line 21

def set_token(token)
  @token = token
end

#show_back_buttonObject



29
30
31
# File 'lib/alexa_toolbox/display_directive_template.rb', line 29

def show_back_button
  @back_button = "VISIBLE"
end