Class: Slackened::BlockKit::Blocks::Section

Inherits:
Base
  • Object
show all
Defined in:
lib/slackened/block_kit/blocks/section.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(*fields) ⇒ Section

rubocop:disable Metrics/MethodLength

Raises:



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

def initialize(*fields) # rubocop:disable Metrics/MethodLength
  raise MaximumFieldsError, "#{fields.count} can't be greater than #{MAX_LENGTH}" if fields.length > MAX_LENGTH
  raise MustBeString unless fields.all? { |f| f.is_a? String }

  if fields.one?
    set({
      type: :section,
      text: Text.new(fields.first)
    })

    return self
  end

  set({
    type: :section,
    fields: fields.map { |f| Text.new(f) }
  })

  self
end