Sha256: aea2b989222f2adc8f0b261512d2aeab6eded26a50ec6e63cd931047bf6517c3

Contents?: true

Size: 890 Bytes

Versions: 14

Compression:

Stored size: 890 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, initial: false)
          @options << Option.new(text: text, value: value, emoji: emoji, initial: initial)

          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 & 1 rubygems

Version Path
slack-ruby-block-kit-0.24.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.23.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.22.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.21.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.20.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.19.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.18.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.17.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.16.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.15.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.14.1 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.14.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.13.0 lib/slack/block_kit/composition/option_group.rb
slack-ruby-block-kit-0.12.0 lib/slack/block_kit/composition/option_group.rb