Class: Slack::BlockKit::Block::SectionBlock
- Inherits:
-
Slack::BlockKit::Block
- Object
- Slack::BlockKit::Block
- Slack::BlockKit::Block::SectionBlock
- Defined in:
- lib/slack/block_kit/block/section_block.rb
Instance Attribute Summary collapse
-
#accessory ⇒ Object
Returns the value of attribute accessory.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from Slack::BlockKit::Block
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ SectionBlock
constructor
A new instance of SectionBlock.
- #to_h ⇒ Object
-
#valid? ⇒ Boolean
Either text or fields must exist and be non-empty.
Methods inherited from Slack::BlockKit::Block
Constructor Details
#initialize ⇒ SectionBlock
Returns a new instance of SectionBlock.
17 18 19 |
# File 'lib/slack/block_kit/block/section_block.rb', line 17 def initialize @fields = TypeRestrictedArray.new(CompositionObjects::Text) end |
Instance Attribute Details
#accessory ⇒ Object
Returns the value of attribute accessory.
8 9 10 |
# File 'lib/slack/block_kit/block/section_block.rb', line 8 def accessory @accessory end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/slack/block_kit/block/section_block.rb', line 8 def fields @fields end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/slack/block_kit/block/section_block.rb', line 8 def text @text end |
Class Method Details
.populate(hash, object) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/slack/block_kit/block/section_block.rb', line 10 def self.populate(hash, object) object.accessory = hash[:accessory] if hash.key?(:accessory) if hash.key?(:text) then object.text = hash[:text] elsif hash.key?(:fields) then hash[:fields].each(&object.fields.method(:<<)) end end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slack/block_kit/block/section_block.rb', line 40 def to_h if text && text.text.size > 3000 raise RangeError, 'text in SectionBlock has max 3000 characters' end super.merge( block_id: block_id, text: text&.to_h, fields: fields.map(&:to_h), accessory: accessory&.to_h ).compact end |
#valid? ⇒ Boolean
Either text or fields must exist and be non-empty.
22 23 24 25 26 |
# File 'lib/slack/block_kit/block/section_block.rb', line 22 def valid? if @text.nil? || @text.empty? then !@fields.empty? else !@text&.empty? end end |