Class: Slack::BlockKit::CompositionObjects::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/block_kit/composition_objects/text.rb

Constant Summary collapse

PLAINTEXT =
:plain_text
MRKDWN =
:mrkdwn
NEWLINE =
"\n"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emojiObject (readonly)

Returns the value of attribute emoji.



8
9
10
# File 'lib/slack/block_kit/composition_objects/text.rb', line 8

def emoji
  @emoji
end

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/slack/block_kit/composition_objects/text.rb', line 8

def text
  @text
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/slack/block_kit/composition_objects/text.rb', line 8

def type
  @type
end

#verbatimObject (readonly)

Returns the value of attribute verbatim.



8
9
10
# File 'lib/slack/block_kit/composition_objects/text.rb', line 8

def verbatim
  @verbatim
end

Class Method Details

.[](hash) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# 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

Instance Method Details

#emoji!Object



29
30
31
# File 'lib/slack/block_kit/composition_objects/text.rb', line 29

def emoji!
  @emoji = true
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/slack/block_kit/composition_objects/text.rb', line 25

def empty?
  text&.empty?
end

#to_hObject



52
53
54
55
56
57
# File 'lib/slack/block_kit/composition_objects/text.rb', line 52

def to_h
  { type: type,
    text: text,
    emoji: emoji,
    verbatim: verbatim }.compact
end

#verbatim!Object



33
34
35
# File 'lib/slack/block_kit/composition_objects/text.rb', line 33

def verbatim!
  @verbatim = true
end