Class: Slack::BlockKit::Element::StaticSelectElement
- Inherits:
-
SelectElement
- Object
- Slack::BlockKit::Element
- SelectElement
- Slack::BlockKit::Element::StaticSelectElement
- Defined in:
- lib/slack/block_kit/element/static_select_element.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#initial_option ⇒ Object
Returns the value of attribute initial_option.
-
#option_groups ⇒ Object
readonly
Returns the value of attribute option_groups.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from SelectElement
Attributes inherited from Slack::BlockKit::Element
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ StaticSelectElement
constructor
A new instance of StaticSelectElement.
- #to_h ⇒ Object
-
#valid? ⇒ Boolean
Either options or option_groups must exist and be non-empty.
Methods inherited from Slack::BlockKit::Element
Constructor Details
#initialize ⇒ StaticSelectElement
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_option ⇒ Object
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_groups ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/slack/block_kit/element/static_select_element.rb', line 8 def @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..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_h ⇒ Object
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: .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.
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 |