Class: ChatSDK::Cards::ActionsContext

Inherits:
Object
  • Object
show all
Defined in:
lib/chat_sdk/cards/actions_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActionsContext

Returns a new instance of ActionsContext.



8
9
10
# File 'lib/chat_sdk/cards/actions_context.rb', line 8

def initialize
  @nodes = []
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



6
7
8
# File 'lib/chat_sdk/cards/actions_context.rb', line 6

def nodes
  @nodes
end

Instance Method Details

#button(text, id:, style: nil, value: nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/chat_sdk/cards/actions_context.rb', line 12

def button(text, id:, style: nil, value: nil)
  attrs = {text: text, id: id}
  attrs[:style] = style if style
  attrs[:value] = value if value
  @nodes << Node.new(:button, attributes: attrs)
end


19
20
21
# File 'lib/chat_sdk/cards/actions_context.rb', line 19

def link_button(text, url:)
  @nodes << Node.new(:link_button, attributes: {text: text, url: url})
end

#select(id:, placeholder: nil, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/chat_sdk/cards/actions_context.rb', line 23

def select(id:, placeholder: nil, &block)
  ctx = SelectContext.new
  ctx.instance_eval(&block)
  attrs = {id: id}
  attrs[:placeholder] = placeholder if placeholder
  @nodes << Node.new(:select, attributes: attrs, children: ctx.nodes)
end