class Slack::BlockKit::CompositionObjects::Text

Constants

MRKDWN
NEWLINE
PLAINTEXT

Attributes

emoji[R]
text[R]
type[R]
verbatim[R]

Public Class Methods

[](hash) click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 14
def self.[](hash)
  new.tap do |object|
    object.type = hash.keys.find { |key| [PLAINTEXT, MRKDWN].include?(key) }
    raise ArgumentError, 'type must be `plain_text` or `mrkdwn`' unless object.type

    object.text = hash[object.type]
    object.emoji! if hash[:emoji]
    object.verbatim! if hash[:verbatim]
  end
end

Public Instance Methods

emoji!() click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 29
def emoji!
  @emoji = true
end
empty?() click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 25
def empty?
  text&.empty?
end
text=(text) click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 45
def text=(text)
  text = text.join(NEWLINE) if text.is_a?(Array)
  raise TypeError, 'text must be a string' unless text.respond_to?(:to_str)

  @text = text.to_s
end
to_h() click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 52
def to_h
  { type: type,
    text: text,
    emoji: emoji,
    verbatim: verbatim }.compact
end
type=(type) click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 37
def type=(type)
  unless [PLAINTEXT, MRKDWN].include?(type.to_sym)
    raise ArgumentError, 'type must be `plain_text` or `mrkdwn`'
  end

  @type = type.to_sym
end
verbatim!() click to toggle source
# File lib/slack/block_kit/composition_objects/text.rb, line 33
def verbatim!
  @verbatim = true
end