Class: MsTeamsHermes::Components::AdaptiveCard

Inherits:
Base
  • Object
show all
Defined in:
lib/msteams_hermes/components/adaptive_card.rb

Overview

A class representing Microsoft’s AdaptiveCard object adaptivecards.io/explorer/AdaptiveCard.html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, actions: nil, entities: [], width: Style::Width::DEFAULT) ⇒ AdaptiveCard

Returns a new instance of AdaptiveCard.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 19

def initialize(body:, actions: nil, entities: [], width: Style::Width::DEFAULT)
  @body = body
  raise "AdaptiveCard `body` must be an Array" unless @body.is_a? Array

  @actions = actions
  raise "AdaptiveCard `actions` must be an Array" unless @actions.nil? || @actions.is_a?(Array)

  @entities = entities
  raise "AdaptiveCard `entities` must be an Array" unless @entities.nil? || @entities.is_a?(Array)

  @width = width
  raise "AdaptiveCard `width` must be one of the available Width options" unless Style::Width.all.include?(width)
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



17
18
19
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 17

def actions
  @actions
end

#bodyObject (readonly)

Returns the value of attribute body.



17
18
19
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 17

def body
  @body
end

#entitiesObject (readonly)

Returns the value of attribute entities.



17
18
19
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 17

def entities
  @entities
end

#widthObject (readonly)

Returns the value of attribute width.



17
18
19
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 17

def width
  @width
end

Instance Method Details

#to_hashObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/msteams_hermes/components/adaptive_card.rb', line 33

def to_hash
  {
    type: "AdaptiveCard",
    version: "1.5",
    body: body.map(&:to_hash),
    actions: actions&.map(&:to_hash),
    msteams: {
      entities: entities.map(&:to_hash),
      width:
    }
  }
end