Class: Slack::BlockKit::Composition::OptionGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/block_kit/composition/option_group.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, emoji: nil) {|_self| ... } ⇒ OptionGroup

Returns a new instance of OptionGroup.

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
18
# File 'lib/slack/block_kit/composition/option_group.rb', line 13

def initialize(label:, emoji: nil)
  @label = PlainText.new(text: label, emoji: emoji)
  @options = []

  yield(self) if block_given?
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/slack/block_kit/composition/option_group.rb', line 11

def options
  @options
end

Instance Method Details

#as_jsonObject



26
27
28
29
30
31
# File 'lib/slack/block_kit/composition/option_group.rb', line 26

def as_json(*)
  {
    label: @label.as_json,
    options: @options.map(&:as_json)
  }
end

#option(text:, value:, emoji: nil, initial: false) ⇒ Object



20
21
22
23
24
# File 'lib/slack/block_kit/composition/option_group.rb', line 20

def option(text:, value:, emoji: nil, initial: false)
  @options << Option.new(text: text, value: value, emoji: emoji, initial: initial)

  self
end