Class: AlexaToolbox::DisplayDirectiveImage

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

Overview

Handles creating display directives in responses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_description = "", url = nil) ⇒ DisplayDirectiveImage

Returns a new instance of DisplayDirectiveImage.



8
9
10
11
12
13
14
# File 'lib/alexa_toolbox/display_directive_image.rb', line 8

def initialize(content_description = "", url = nil)
  @content_description = content_description
  @sources = []
  if !url.nil?
    self.add_xsmall_source(url)
  end
end

Instance Attribute Details

#content_descriptionObject

Returns the value of attribute content_description.



6
7
8
# File 'lib/alexa_toolbox/display_directive_image.rb', line 6

def content_description
  @content_description
end

#sourcesObject

Returns the value of attribute sources.



6
7
8
# File 'lib/alexa_toolbox/display_directive_image.rb', line 6

def sources
  @sources
end

Instance Method Details

#add_large_source(url) ⇒ Object



51
52
53
54
55
56
# File 'lib/alexa_toolbox/display_directive_image.rb', line 51

def add_large_source(url)
  @sources.push({
    url: url,
    size: "LARGE"
  })
end

#add_medium_source(url) ⇒ Object



44
45
46
47
48
49
# File 'lib/alexa_toolbox/display_directive_image.rb', line 44

def add_medium_source(url)
  @sources.push({
    url: url,
    size: "MEDIUM"
  })
end

#add_small_source(url) ⇒ Object



37
38
39
40
41
42
# File 'lib/alexa_toolbox/display_directive_image.rb', line 37

def add_small_source(url)
  @sources.push({
    url: url,
    size: "SMALL"
  })
end

#add_source(url, size = "X_SMALL", widthPixels = nil, heightPixels = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/alexa_toolbox/display_directive_image.rb', line 20

def add_source(url,size = "X_SMALL",widthPixels = nil,heightPixels = nil)
  source = {
    url: url,
    size: size
  }
  source[:widthPixels] = widthPixels if !widthPixels.nil?
  source[:heightPixels] = heightPixels if !heightPixels.nil?
  @sources.push(source)
end

#add_xlarge_source(url) ⇒ Object



58
59
60
61
62
63
# File 'lib/alexa_toolbox/display_directive_image.rb', line 58

def add_xlarge_source(url)
  @sources.push({
    url: url,
    size: "X_LARGE"
  })
end

#add_xsmall_source(url) ⇒ Object



30
31
32
33
34
35
# File 'lib/alexa_toolbox/display_directive_image.rb', line 30

def add_xsmall_source(url)
  @sources.push({
    url: url,
    size: "X_SMALL"
  })
end

#buildObject



69
70
71
72
73
74
75
# File 'lib/alexa_toolbox/display_directive_image.rb', line 69

def build
  data_hash = {
    contentDescription: @content_description,
    sources: @sources
  }
  data_hash
end

#set_content_description(text) ⇒ Object



16
17
18
# File 'lib/alexa_toolbox/display_directive_image.rb', line 16

def set_content_description(text)
  @content_description = text
end

#valid?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/alexa_toolbox/display_directive_image.rb', line 65

def valid?
  @content_description.length > 0 && @sources.count > 0
end