Class: BlockKit::Types::Text

Inherits:
ActiveModel::Type::Value
  • Object
show all
Includes:
Singleton
Defined in:
lib/block_kit/types/text.rb

Direct Known Subclasses

Mrkdwn, PlainText

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/block_kit/types/text.rb', line 15

def cast(value)
  case value
  when Composition::PlainText, Composition::Mrkdwn, NilClass
    value
  when Hash
    # Check for a `:type` key, otherwise prefer Mrkdwn over PlainText except
    # in the explicit case where only the `:text` and `:emoji` keys are provided
    type = value[:type]&.to_sym
    if type == :mrkdwn
      Mrkdwn.instance.cast(value)
    elsif type == :plain_text
      PlainText.instance.cast(value)
    elsif value.key?(:verbatim) || !value.key?(:emoji)
      Mrkdwn.instance.cast(value)
    else
      PlainText.instance.cast(value)
    end
  else
    Mrkdwn.instance.cast(value)
  end
end

#typeObject



11
12
13
# File 'lib/block_kit/types/text.rb', line 11

def type
  :block_kit_text
end