Sha256: b7082ea5beb32aa542692aa298e2284ac16161f5e2facc18cb864f7faf906672

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Slack
  module BlockKit
    module CompositionObjects
      class Filter
        using Refinements::HashCompact
        attr_reader :include, :exclude_external_shared_channels, :exclude_bot_users

        def self.[](hash)
          new.tap do |object|
            hash[:include].each(&object.include.method(:<<))
            object.exclude_external_shared_channels! if hash[:exclude_external_shared_channels]
            object.exclude_bot_users! if hash[:exclude_bot_users]
          end
        end

        def initialize
          @include = TypeRestrictedArray.new(String)
        end

        def exclude_external_shared_channels!
          @exclude_external_shared_channels = true
        end

        def exclude_bot_users!
          @exclude_bot_users = true
        end

        def to_h
          { include: self.include,
            exclude_external_shared_channels: exclude_external_shared_channels,
            exclude_bot_users: exclude_bot_users }.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/composition_objects/filter.rb