Class: Slackened::BlockKit::Blocks::Context

Inherits:
Base
  • Object
show all
Defined in:
lib/slackened/block_kit/blocks/context.rb

Constant Summary collapse

MAX_LENGTH =
10

Instance Attribute Summary

Attributes inherited from Base

#block

Instance Method Summary collapse

Methods inherited from Base

#set, #to_h

Constructor Details

#initialize(*elements) ⇒ Context

Returns a new instance of Context.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slackened/block_kit/blocks/context.rb', line 12

def initialize(*elements)
	raise MaximumElementsError, "#{elements.count} can't be greater than #{MAX_LENGTH}" if elements.length > MAX_LENGTH

	# TODO: need to allow for image
	# https://api.slack.com/reference/block-kit/blocks#context
	set({
		type: :context,
		elements: elements.map do |element|
			raise MustBeString, "#{element} must be a string" unless element.is_a? String

			Text.new(element)
		end
	})

	self
end