Class: Slack::BlockKit::Block::ContextBlock

Inherits:
Slack::BlockKit::Block show all
Defined in:
lib/slack/block_kit/block/context_block.rb

Instance Attribute Summary collapse

Attributes inherited from Slack::BlockKit::Block

#block_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Slack::BlockKit::Block

[], #type

Constructor Details

#initializeContextBlock

Returns a new instance of ContextBlock.



14
15
16
# File 'lib/slack/block_kit/block/context_block.rb', line 14

def initialize
  @elements = TypeRestrictedArray.new(Element, CompositionObjects::Text)
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



8
9
10
# File 'lib/slack/block_kit/block/context_block.rb', line 8

def elements
  @elements
end

Class Method Details

.populate(hash, object) ⇒ Object



10
11
12
# File 'lib/slack/block_kit/block/context_block.rb', line 10

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

Instance Method Details

#to_hObject



22
23
24
25
26
# File 'lib/slack/block_kit/block/context_block.rb', line 22

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

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/slack/block_kit/block/context_block.rb', line 18

def valid?
  !@elements.empty?
end