Class: Slack::BlockKit::Element::StaticSelectElement

Inherits:
SelectElement show all
Defined in:
lib/slack/block_kit/element/static_select_element.rb

Direct Known Subclasses

MultiStaticSelectElement

Instance Attribute Summary collapse

Attributes inherited from SelectElement

#confirm, #placeholder

Attributes inherited from Slack::BlockKit::Element

#action_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Slack::BlockKit::Element

[], #type

Constructor Details

#initializeStaticSelectElement

Returns a new instance of StaticSelectElement.



18
19
20
21
# File 'lib/slack/block_kit/element/static_select_element.rb', line 18

def initialize
  @options = TypeRestrictedArray.new(CompositionObjects::Option)
  @option_groups = TypeRestrictedArray.new(CompositionObjects::OptionGroup)
end

Instance Attribute Details

#initial_optionObject

Returns the value of attribute initial_option.



8
9
10
# File 'lib/slack/block_kit/element/static_select_element.rb', line 8

def initial_option
  @initial_option
end

#option_groupsObject (readonly)

Returns the value of attribute option_groups.



8
9
10
# File 'lib/slack/block_kit/element/static_select_element.rb', line 8

def option_groups
  @option_groups
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/slack/block_kit/element/static_select_element.rb', line 8

def options
  @options
end

Class Method Details

.populate(hash, object) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/slack/block_kit/element/static_select_element.rb', line 10

def self.populate(hash, object)
  hash[:options].each(&object.options.method(:<<)) if hash.key?(:options)
  hash[:option_groups].each(&object.option_groups.method(:<<)) if hash.key?(:option_groups)
  object.initial_option = hash[:initial_option] if hash.key?(:initial_option)

  super(hash, object)
end

Instance Method Details

#to_hObject



36
37
38
39
40
41
42
# File 'lib/slack/block_kit/element/static_select_element.rb', line 36

def to_h
  super.merge(
    options: options.map(&:to_h),
    option_groups: option_groups.map(&:to_h),
    initial_option: initial_option&.to_h
  ).compact
end

#valid?Boolean

Either options or option_groups must exist and be non-empty.

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/slack/block_kit/element/static_select_element.rb', line 24

def valid?
  if @options.nil? || @options.empty? then !@option_groups.empty?
  else !@options&.empty?
  end
end