Sha256: 14f0ebfb2b1311732c8b512d51833876e9bf10732fcdceab05ede3fe2a5930e0

Contents?: true

Size: 856 Bytes

Versions: 14

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module Composition
      # Provides a way to group options in a select menu.
      #
      # https://api.slack.com/reference/messaging/composition-objects#option-group
      # https://api.slack.com/reference/messaging/block-elements#select
      class OptionGroup
        attr_accessor :options

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

          yield(self) if block_given?
        end

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

          self
        end

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

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
slack-ruby-block-kit-0.11.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.10.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.9.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.8.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.7.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.6.1 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.6.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.5.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.4.0 lib/slack/block_kit/composition/option_group.rb
slack_block_kit-0.3.3 lib/slack/block_kit/composition/option_group.rb
slack_block_kit-0.3.2 lib/slack/block_kit/composition/option_group.rb
slack_block_kit-0.3.1 lib/slack/block_kit/composition/option_group.rb
slack_block_kit-0.3.0 lib/slack/block_kit/composition/option_group.rb
slack_block_kit-0.2.0 lib/slack/block_kit/composition/option_group.rb