Sha256: 3b9594c3ead1d49222a4ecf03893a2a7bd5286ab96b3842cb992285e8e1e36ed

Contents?: true

Size: 767 Bytes

Versions: 1

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    class Block
      class ActionsBlock < Block
        using Refinements::HashCompact
        attr_accessor :elements

        def self.populate(hash, object)
          hash[:elements].each(&object.elements.method(:<<))
        end

        def initialize
          @elements = TypeRestrictedArray.new(
            Element::ButtonElement,
            Element::SelectElement,
            Element::OverflowElement,
            Element::DatePickerElement
          )
        end

        def valid?
          !@elements.empty? && @elements.size <= 5
        end

        def to_h
          super.merge(
            elements: elements.map(&:to_h)
          ).compact
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-block-kit-0.1.0 lib/slack/block_kit/block/actions_block.rb